Skip to content

Commit 124b1cb

Browse files
youknowriaddmsnell
authored andcommitted
Build/Test Tools: Add missing tools/webpack/development.js
Adds the missing `tools/webpack/development.js` file that was inadvertently omitted from [61487]. See #64393. git-svn-id: https://develop.svn.wordpress.org/trunk@61488 602fd350-edb4-49c9-b593-d223f7449a82 (cherry picked from commit 1af331f)
1 parent 0416c15 commit 124b1cb

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

tools/webpack/development.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* External dependencies
3+
*/
4+
const TerserPlugin = require( 'terser-webpack-plugin' );
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
const { baseDir } = require( './shared' );
10+
11+
/**
12+
* Webpack configuration for development scripts (React Refresh).
13+
*
14+
* These scripts enable hot module replacement for block development
15+
* when using `@wordpress/scripts` with the `--hot` flag.
16+
*
17+
* @param {Object} env Environment options.
18+
* @param {string} env.buildTarget Build target directory.
19+
* @param {boolean} env.watch Whether to watch for changes.
20+
* @return {Object} Webpack configuration object.
21+
*/
22+
module.exports = function( env = { buildTarget: 'src/', watch: false } ) {
23+
const buildTarget = env.buildTarget || 'src/';
24+
25+
const entry = {
26+
// React Refresh runtime - exposes ReactRefreshRuntime global.
27+
[ buildTarget + 'wp-includes/js/dist/development/react-refresh-runtime.js' ]: {
28+
import: 'react-refresh/runtime',
29+
library: {
30+
name: 'ReactRefreshRuntime',
31+
type: 'window',
32+
},
33+
},
34+
[ buildTarget + 'wp-includes/js/dist/development/react-refresh-runtime.min.js' ]: {
35+
import: 'react-refresh/runtime',
36+
library: {
37+
name: 'ReactRefreshRuntime',
38+
type: 'window',
39+
},
40+
},
41+
// React Refresh entry - injects runtime into global hook before React loads.
42+
[ buildTarget + 'wp-includes/js/dist/development/react-refresh-entry.js' ]:
43+
'@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js',
44+
[ buildTarget + 'wp-includes/js/dist/development/react-refresh-entry.min.js' ]:
45+
'@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js',
46+
};
47+
48+
return {
49+
target: 'browserslist',
50+
// Must use development mode to preserve process.env.NODE_ENV checks
51+
// in the source files. These scripts are only used during development.
52+
mode: 'development',
53+
devtool: false,
54+
cache: true,
55+
entry,
56+
output: {
57+
path: baseDir,
58+
filename: '[name]',
59+
},
60+
optimization: {
61+
minimize: true,
62+
moduleIds: 'deterministic',
63+
minimizer: [
64+
new TerserPlugin( {
65+
include: /\.min\.js$/,
66+
extractComments: false,
67+
} ),
68+
],
69+
},
70+
watch: env.watch,
71+
};
72+
};

0 commit comments

Comments
 (0)