diff --git a/tools/webpack/blocks.js b/tools/webpack/blocks.js index 94b5cb57b2272..91e2cfafbdf84 100644 --- a/tools/webpack/blocks.js +++ b/tools/webpack/blocks.js @@ -1,7 +1,6 @@ /** * External dependencies */ -const { DefinePlugin } = require( 'webpack' ); const CopyWebpackPlugin = require( 'copy-webpack-plugin' ); /** @@ -12,7 +11,7 @@ const DependencyExtractionPlugin = require( '@wordpress/dependency-extraction-we /** * Internal dependencies */ -const { normalizeJoin, stylesTransform, baseConfig, baseDir } = require( './shared' ); +const { baseDir, getBaseConfig, normalizeJoin, stylesTransform } = require( './shared' ); const { isDynamic, toDirectoryName, @@ -62,8 +61,9 @@ module.exports = function( env = { environment: 'production', watch: false, buil noErrorOnMissing: true, } ) ); + const baseConfig = getBaseConfig( env ); const config = { - ...baseConfig( env ), + ...baseConfig, entry: { 'navigation/view': normalizeJoin( baseDir, 'node_modules/@wordpress/block-library/build-module/navigation/view' ), 'image/view': normalizeJoin( baseDir, 'node_modules/@wordpress/block-library/build-module/image/view' ), @@ -127,13 +127,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil ], }, plugins: [ - new DefinePlugin( { - // Inject the `IS_GUTENBERG_PLUGIN` global, used for feature flagging. - 'process.env.IS_GUTENBERG_PLUGIN': false, - 'process.env.FORCE_REDUCED_MOTION': JSON.stringify( - process.env.FORCE_REDUCED_MOTION, - ), - } ), + ...baseConfig.plugins, new DependencyExtractionPlugin( { injectPolyfill: false, useDefaults: false, diff --git a/tools/webpack/packages.js b/tools/webpack/packages.js index 65747bdf8e2ba..783f5b3321953 100644 --- a/tools/webpack/packages.js +++ b/tools/webpack/packages.js @@ -1,7 +1,6 @@ /** * External dependencies */ -const { DefinePlugin } = require( 'webpack' ); const CopyWebpackPlugin = require( 'copy-webpack-plugin' ); const LiveReloadPlugin = require( 'webpack-livereload-plugin' ); const UglifyJS = require( 'uglify-js' ); @@ -17,7 +16,7 @@ const DependencyExtractionPlugin = require( '@wordpress/dependency-extraction-we /** * Internal dependencies */ -const { normalizeJoin, stylesTransform, baseConfig, baseDir } = require( './shared' ); +const { baseDir, getBaseConfig, normalizeJoin, stylesTransform } = require( './shared' ); const { dependencies } = require( '../../package' ); const exportDefaultPackages = [ @@ -129,8 +128,9 @@ module.exports = function( env = { environment: 'production', watch: false, buil to: normalizeJoin(baseDir, `src/${ phpFiles[ filename ] }` ), } ) ); + const baseConfig = getBaseConfig( env ); const config = { - ...baseConfig( env ), + ...baseConfig, entry: packages.reduce( ( memo, packageName ) => { memo[ packageName ] = { import: normalizeJoin(baseDir, `node_modules/@wordpress/${ packageName }` ), @@ -151,15 +151,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil path: normalizeJoin(baseDir, `${ buildTarget }/js/dist` ), }, plugins: [ - new DefinePlugin( { - // Inject the `IS_GUTENBERG_PLUGIN` global, used for feature flagging. - 'process.env.IS_GUTENBERG_PLUGIN': false, - // Inject the `IS_WORDPRESS_CORE` global, used for feature flagging. - 'process.env.IS_WORDPRESS_CORE': true, - 'process.env.FORCE_REDUCED_MOTION': JSON.stringify( - process.env.FORCE_REDUCED_MOTION - ), - } ), + ...baseConfig.plugins, new DependencyExtractionPlugin( { injectPolyfill: true, combineAssets: true, diff --git a/tools/webpack/shared.js b/tools/webpack/shared.js index f6930d5e6ef7f..5aea4204d31a2 100644 --- a/tools/webpack/shared.js +++ b/tools/webpack/shared.js @@ -1,13 +1,14 @@ /** * External dependencies */ +const { DefinePlugin } = require( 'webpack' ); const TerserPlugin = require( 'terser-webpack-plugin' ); const postcss = require( 'postcss' ); const { join } = require( 'path' ); const baseDir = join( __dirname, '../../' ); -const baseConfig = ( env ) => { +const getBaseConfig = ( env ) => { const mode = env.environment; const config = { @@ -41,6 +42,16 @@ const baseConfig = ( env ) => { }, stats: 'errors-only', watch: env.watch, + plugins: [ + new DefinePlugin( { + // Inject the `IS_GUTENBERG_PLUGIN` global, used for feature flagging. + 'process.env.IS_GUTENBERG_PLUGIN': false, + // Inject the `IS_WORDPRESS_CORE` global, used for feature flagging. + 'process.env.IS_WORDPRESS_CORE': true, + // Inject the `SCRIPT_DEBUG` global, used for dev versions of JavaScript. + SCRIPT_DEBUG: mode === 'development', + } ), + ], }; if ( mode === 'development' && env.buildTarget === 'build/' ) { @@ -79,7 +90,7 @@ const normalizeJoin = ( ...paths ) => join( ...paths ).replace( /\\/g, '/' ); module.exports = { baseDir, - baseConfig, + getBaseConfig, normalizeJoin, stylesTransform, };