Skip to content

Commit

Permalink
Scripts: Allow WP_DEVTOOL to set devtool in prod builds (#46812)
Browse files Browse the repository at this point in the history
* Allow WP_DEVTOOL to set devtool in prod builds

* Add changelog entry
  • Loading branch information
noahtallen committed Feb 2, 2023
1 parent 0fbd15a commit f3912fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
4 changes: 4 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### New Features

- The `WP_DEVTOOL` environment variable can now be used to set the Webpack devtool option for sourcemaps in production builds ([#46812](https://github.com/WordPress/gutenberg/pull/46812)). Previously, this only worked for development builds.

## 25.3.0 (2023-02-01)

## 25.2.0 (2023-01-11)
Expand Down
27 changes: 18 additions & 9 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,15 @@ const config = {
},
};

// WP_DEVTOOL global variable controls how source maps are generated.
// See: https://webpack.js.org/configuration/devtool/#devtool.
if ( process.env.WP_DEVTOOL ) {
config.devtool = process.env.WP_DEVTOOL;
}

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: /\.(j|t)sx?$/,
exclude: [ /node_modules/ ],
use: require.resolve( 'source-map-loader' ),
enforce: 'pre',
} );
// Set default sourcemap mode if it wasn't set by WP_DEVTOOL.
config.devtool = config.devtool || 'source-map';
config.devServer = {
devMiddleware: {
writeToDisk: true,
Expand All @@ -323,4 +322,14 @@ if ( ! isProduction ) {
};
}

// Add source-map-loader if devtool is set, whether in dev mode or not.
if ( config.devtool ) {
config.module.rules.unshift( {
test: /\.(j|t)sx?$/,
exclude: [ /node_modules/ ],
use: require.resolve( 'source-map-loader' ),
enforce: 'pre',
} );
}

module.exports = config;

1 comment on commit f3912fa

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in f3912fa.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4072224290
📝 Reported issues:

Please sign in to comment.