Skip to content

Commit

Permalink
fix(docz-core): add happypack again 😢
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Nov 15, 2018
1 parent ea9a864 commit f0e219e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 24 deletions.
1 change: 1 addition & 0 deletions packages/docz-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"friendly-errors-webpack-plugin": "^1.7.0",
"fs-extra": "^7.0.1",
"get-pkg-repo": "^4.0.2",
"happypack": "^5.0.0",
"html-minifier": "^3.5.21",
"humanize-string": "^1.0.2",
"koa": "^2.6.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/docz-core/src/webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,13 @@ export const createConfig = (args: Args, env: Env) => async (
* loaders
*/

loaders.js(config, args, babelrc)
loaders.mdx(config, args, babelrc)
loaders.js(config, args)
loaders.mdx(config, args)
loaders.images(config)
loaders.svg(config)
loaders.media(config)
loaders.fonts(config)
loaders.setupHappypack(config, args, babelrc)

/**
* plugins
Expand Down
71 changes: 50 additions & 21 deletions packages/docz-core/src/webpack/loaders.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,57 @@
import * as path from 'path'
import HappyPack from 'happypack'

import Config from 'webpack-chain'
import { Config as Args } from '../commands/args'
import * as paths from '../config/paths'
import * as mdxConfig from '../config/mdx'

const addCacheLoader = (rule: Config.Rule) =>
rule
.use('cache-loader')
.loader(require.resolve('cache-loader'))
.options({ cacheDirectory: paths.cache })
export const setupHappypack = (config: Config, args: Args, babelrc: any) => {
const jsx = {
id: 'jsx',
verbose: args.debug,
loaders: [
!args.debug && {
loader: require.resolve('cache-loader'),
options: {
cacheDirectory: paths.cache,
},
},
{
loader: require.resolve('babel-loader'),
options: babelrc,
},
].filter(Boolean) as any[],
}

const addTypescriptDocgen = (rule: Config.Rule) =>
rule
.use('typescript-docgen')
.loader(require.resolve('react-docgen-typescript-loader'))
if (args.propsParser && args.typescript) {
jsx.loaders.push({
loader: require.resolve('react-docgen-typescript-loader'),
})
}

const mdx = {
id: 'mdx',
verbose: args.debug,
loaders: [
!args.debug && {
loader: require.resolve('cache-loader'),
options: {
cacheDirectory: paths.cache,
},
},
{
loader: require.resolve('babel-loader'),
options: babelrc,
},
].filter(Boolean),
}

export const js = (config: Config, args: Args, babelrc: any) => {
config.plugin('happypack-jsx').use(HappyPack, [jsx])
config.plugin('happypack-mdx').use(HappyPack, [mdx])
}

export const js = (config: Config, args: Args) => {
const srcPath = path.resolve(paths.root, args.src)

config.module
Expand All @@ -28,15 +63,11 @@ export const js = (config: Config, args: Args, babelrc: any) => {
.end()
.exclude.add(/node_modules/)
.end()
.when(!args.debug, addCacheLoader)
.use('babel-loader')
.loader(require.resolve('babel-loader'))
.options(babelrc)
.end()
.when(args.propsParser && args.typescript, addTypescriptDocgen)
.use('happypack-jsx')
.loader('happypack/loader?id=jsx')
}

export const mdx = (config: Config, args: Args, babelrc: any) => {
export const mdx = (config: Config, args: Args) => {
const { mdPlugins, hastPlugins } = args
const srcPath = path.resolve(paths.root, args.src)

Expand All @@ -47,10 +78,8 @@ export const mdx = (config: Config, args: Args, babelrc: any) => {
.end()
.exclude.add(/node_modules/)
.end()
.when(!args.debug, addCacheLoader)
.use('babel-loader')
.loader(require.resolve('babel-loader'))
.options(babelrc)
.use('happypack-mdx')
.loader('happypack/loader?id=mdx')
.end()
.use('mdx-loader')
.loader(require.resolve('@mdx-js/loader'))
Expand Down
22 changes: 21 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2866,6 +2866,11 @@ async-limiter@~1.0.0:
resolved "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8"
integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==

async@1.5.0:
version "1.5.0"
resolved "http://registry.npmjs.org/async/-/async-1.5.0.tgz#2796642723573859565633fc6274444bee2f8ce3"
integrity sha1-J5ZkJyNXOFlWVjP8YnRES+4vjOM=

async@^2.0.0, async@^2.0.0-rc.1, async@^2.1.4, async@^2.5.0:
version "2.6.1"
resolved "https://registry.npmjs.org/async/-/async-2.6.1.tgz#b245a23ca71930044ec53fa46aa00a3e87c6a610"
Expand Down Expand Up @@ -6762,6 +6767,16 @@ handlebars@^4.0.2:
optionalDependencies:
uglify-js "^3.1.4"

happypack@^5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/happypack/-/happypack-5.0.0.tgz#59606b6161acfbd69e99072e5c63f5d165e48b0e"
integrity sha1-WWBrYWGs+9aemQcuXGP10WXkiw4=
dependencies:
async "1.5.0"
json-stringify-safe "5.0.1"
loader-utils "1.1.0"
serialize-error "^2.1.0"

har-schema@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92"
Expand Down Expand Up @@ -7905,7 +7920,7 @@ json-stable-stringify-without-jsonify@^1.0.1:
resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=

json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
json-stringify-safe@5.0.1, json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=
Expand Down Expand Up @@ -11841,6 +11856,11 @@ sentence-case@^2.1.0:
no-case "^2.2.0"
upper-case-first "^1.1.2"

serialize-error@^2.1.0:
version "2.1.0"
resolved "http://registry.npmjs.org/serialize-error/-/serialize-error-2.1.0.tgz#50b679d5635cdf84667bdc8e59af4e5b81d5f60a"
integrity sha1-ULZ51WNc34Rme9yOWa9OW4HV9go=

serialize-javascript@^1.4.0, serialize-javascript@^1.5.0:
version "1.5.0"
resolved "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-1.5.0.tgz#1aa336162c88a890ddad5384baebc93a655161fe"
Expand Down

0 comments on commit f0e219e

Please sign in to comment.