From ac95d54669607e6326ca327d3b42b8d4762523d3 Mon Sep 17 00:00:00 2001 From: Chi-Hsuan Huang Date: Fri, 15 Apr 2022 12:08:59 +0800 Subject: [PATCH] Add more comments to admin webpacks config & simplify the logic --- plugins/woocommerce-admin/webpack.config.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/woocommerce-admin/webpack.config.js b/plugins/woocommerce-admin/webpack.config.js index 67634a1c9c2..af43fc54f34 100644 --- a/plugins/woocommerce-admin/webpack.config.js +++ b/plugins/woocommerce-admin/webpack.config.js @@ -58,6 +58,7 @@ wpAdminScripts.forEach( ( name ) => { entryPoints[ name ] = `./client/wp-admin-scripts/${ name }`; } ); +// WordPress.org’s translation infrastructure ignores files named “.min.js” so we need to name our JS files without min when releasing the plugin. const suffix = WC_ADMIN_PHASE === 'core' ? '' : '.min'; const webpackConfig = { @@ -181,10 +182,9 @@ const webpackConfig = { // TODO: Partially replace with __webpack_get_script_filename__ in app with Webpack 5.x. // The CSS chunk portion will need to remain, as it originates in MiniCssExtractPlugin. new AsyncChunkSrcVersionParameterPlugin(), - // Generate unminified files to load the unminified version when `define( 'SCRIPT_DEBUG', true );` is set in wp-config. - // This is also required to publish human readeable code in the deployed "plugin". - // See https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#4-code-must-be-mostly-human-readable - WC_ADMIN_PHASE !== 'core' && + // We only want to generate unminified files in the development phase. + WC_ADMIN_PHASE === 'development' && + // Generate unminified files to load the unminified version when `define( 'SCRIPT_DEBUG', true );` is set in wp-config. new UnminifyWebpackPlugin( { test: /\.js($|\?)/i, mainEntry: 'app/index.min.js', @@ -200,7 +200,11 @@ const webpackConfig = { }, }; -if ( webpackConfig.mode !== 'production' && WC_ADMIN_PHASE !== 'core' ) { +// Use the source map if we're in development mode, . +if ( + webpackConfig.mode === 'development' || + WC_ADMIN_PHASE === 'development' +) { webpackConfig.devtool = process.env.SOURCEMAP || 'source-map'; }