diff --git a/package-lock.json b/package-lock.json index cb48f86509a3f..a78ef1fe36a66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3130,6 +3130,7 @@ "source-map-loader": "^0.2.4", "stylelint": "^9.10.1", "stylelint-config-wordpress": "^13.1.0", + "thread-loader": "^2.1.2", "webpack": "4.8.3", "webpack-bundle-analyzer": "^3.0.3", "webpack-cli": "^3.1.2", @@ -20556,9 +20557,9 @@ }, "dependencies": { "ajv": { - "version": "6.9.1", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.9.1.tgz", - "integrity": "sha512-XDN92U311aINL77ieWHmqCcNlwjoP5cHXDxIxbf2MaPYuCXOHS7gHH8jktxeK5omgd52XbSTX6a4Piwd1pQmzA==", + "version": "6.10.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", + "integrity": "sha512-nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYwYVIIH1TvE3tu4OEg==", "dev": true, "requires": { "fast-deep-equal": "^2.0.1", @@ -22138,6 +22139,25 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, + "thread-loader": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/thread-loader/-/thread-loader-2.1.2.tgz", + "integrity": "sha512-7xpuc9Ifg6WU+QYw/8uUqNdRwMD+N5gjwHKMqETrs96Qn+7BHwECpt2Brzr4HFlf4IAkZsayNhmGdbkBsTJ//w==", + "dev": true, + "requires": { + "loader-runner": "^2.3.1", + "loader-utils": "^1.1.0", + "neo-async": "^2.6.0" + }, + "dependencies": { + "neo-async": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.0.tgz", + "integrity": "sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA==", + "dev": true + } + } + }, "throat": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/throat/-/throat-4.1.0.tgz", @@ -23182,9 +23202,9 @@ }, "dependencies": { "ajv": { - "version": "6.9.1", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.9.1.tgz", - "integrity": "sha512-XDN92U311aINL77ieWHmqCcNlwjoP5cHXDxIxbf2MaPYuCXOHS7gHH8jktxeK5omgd52XbSTX6a4Piwd1pQmzA==", + "version": "6.10.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", + "integrity": "sha512-nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYwYVIIH1TvE3tu4OEg==", "dev": true, "requires": { "fast-deep-equal": "^2.0.1", diff --git a/packages/scripts/config/webpack.config.js b/packages/scripts/config/webpack.config.js index 9a1daabf5d752..65ec3878e7808 100644 --- a/packages/scripts/config/webpack.config.js +++ b/packages/scripts/config/webpack.config.js @@ -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( { + test: /\.js$/, + use: require.resolve( 'source-map-loader' ), + enforce: 'pre', + } ); } module.exports = config; diff --git a/packages/scripts/package.json b/packages/scripts/package.json index bbc3cb49f9297..2b378089eef6e 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -50,6 +50,7 @@ "source-map-loader": "^0.2.4", "stylelint": "^9.10.1", "stylelint-config-wordpress": "^13.1.0", + "thread-loader": "^2.1.2", "webpack": "4.8.3", "webpack-bundle-analyzer": "^3.0.3", "webpack-cli": "^3.1.2",