[Experimental] Move Babel transpile into a cached thread pool (#9331)

* Add cached off-thread babel transpile

* Update webpack-config.ts

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
This commit is contained in:
Jason Miller 2019-12-24 10:58:50 -05:00 committed by Tim Neutkens
parent 5909e67765
commit 93c745c2b7
2 changed files with 26 additions and 1 deletions

View file

@ -642,7 +642,30 @@ export default async function getBaseWebpackConfig(
}
return /node_modules/.test(path)
},
use: defaultLoaders.babel,
use: config.experimental.babelMultiThread
? [
// Move Babel transpilation into a thread pool (2 workers, unlimited batch size).
// Applying a cache to the off-thread work avoids paying transfer costs for unchanged modules.
{
loader: 'cache-loader',
options: {
cacheContext: dir,
cacheDirectory: path.join(dir, '.next', 'cache', 'webpack'),
cacheIdentifier: `webpack${isServer ? '-server' : ''}${
config.experimental.modern ? '-hasmodern' : ''
}`,
},
},
{
loader: 'thread-loader',
options: {
workers: 2,
workerParallelJobs: Infinity,
},
},
defaultLoaders.babel,
]
: defaultLoaders.babel,
},
].filter(Boolean),
},

View file

@ -81,6 +81,7 @@
"babel-plugin-syntax-jsx": "6.18.0",
"babel-plugin-transform-define": "2.0.0",
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
"cache-loader": "4.1.0",
"chalk": "2.4.2",
"ci-info": "2.0.0",
"compression": "1.7.4",
@ -128,6 +129,7 @@
"style-loader": "1.0.0",
"styled-jsx": "3.2.4",
"terser": "4.4.2",
"thread-loader": "2.1.3",
"unfetch": "4.1.0",
"url": "0.11.0",
"url-polyfill": "1.1.7",