-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e70e420
Scripts: Use thread-loader in Babel compilation
aduth 2bd36f2
Scripts: Include Sourcemap Loader only in development environments
aduth ec9b584
Scripts: Use cache directory for Babel loader
aduth ba48f76
Fix package-lock.json to stop installing packages locally
gziolo bdc1c22
Tell webpack to look for thread-loader within the scripts node_module…
nosolosw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [ | ||
require.resolve( 'thread-loader' ), | ||
{ | ||
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() && { | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
object destructuring magic :)