-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scripts: Optimize default Webpack configuration #14860
Changes from 4 commits
e70e420
2bd36f2
ec9b584
ba48f76
bdc1c22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,12 +66,6 @@ const externals = [ | |
const isProduction = process.env.NODE_ENV === 'production'; | ||
const mode = isProduction ? 'production' : 'development'; | ||
|
||
const getBabelLoaderOptions = () => hasBabelConfig() ? {} : { | ||
babelrc: false, | ||
configFile: false, | ||
presets: [ require.resolve( '@wordpress/babel-preset-default' ) ], | ||
}; | ||
|
||
const config = { | ||
mode, | ||
entry: { | ||
|
@@ -89,18 +83,29 @@ const config = { | |
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
use: require.resolve( 'source-map-loader' ), | ||
enforce: 'pre', | ||
}, | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: require.resolve( 'babel-loader' ), | ||
options: getBabelLoaderOptions(), | ||
}, | ||
use: [ | ||
'thread-loader', | ||
oandregal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
loader: require.resolve( 'babel-loader' ), | ||
options: { | ||
// Babel uses a directory within local node_modules | ||
// by default. Use the environment variable option | ||
// to enable more persistent caching. | ||
cacheDirectory: process.env.BABEL_CACHE_DIRECTORY || true, | ||
|
||
// Provide a fallback configuration if there's not | ||
// one explicitly available in the project. | ||
...( ! hasBabelConfig() && { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had never liked the options weren't colocated with the loader, so I welcome this change! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. object destructuring magic :) |
||
babelrc: false, | ||
configFile: false, | ||
presets: [ require.resolve( '@wordpress/babel-preset-default' ) ], | ||
} ), | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
|
@@ -121,6 +126,11 @@ if ( ! isProduction ) { | |
// WP_DEVTOOL global variable controls how source maps are generated. | ||
// See: https://webpack.js.org/configuration/devtool/#devtool. | ||
config.devtool = process.env.WP_DEVTOOL || 'source-map'; | ||
config.module.rules.unshift( { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be |
||
test: /\.js$/, | ||
use: require.resolve( 'source-map-loader' ), | ||
enforce: 'pre', | ||
} ); | ||
} | ||
|
||
module.exports = config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
over on Calypso, we found that the optimal number wasn't CPU-1, but more like CPU / 2. MIght be worth experimenting with a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Ben, thanks for checking in. I didn't note it in the original comments, but I did tinker with this value slightly, though in my case I tried increasing it to the exact number of CPUs, and had observed a degraded benefit. I hadn't considered lowering it, but will give it a try.
Is there a pull request or issue which I could reference for that and/or other settings you'd explored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aduth Automattic/wp-calypso#25456 and Automattic/wp-calypso#26059