-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwebpack.config.js
More file actions
61 lines (52 loc) · 1.8 KB
/
Copy pathwebpack.config.js
File metadata and controls
61 lines (52 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const path = require( 'path' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
function resolve( ...paths ) {
return path.resolve( __dirname, ...paths );
}
const plugins = defaultConfig.plugins
.filter(
( plugin ) =>
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
)
.map( ( plugin ) => {
if (
plugin.constructor.name.toLowerCase() === 'minicssextractplugin'
) {
plugin.options.filename = '../css/[name].css';
plugin.options.chunkFilename = '../css/[name].css';
plugin.options.esModule = true;
}
return plugin;
} );
// Re-add DependencyExtractionWebpackPlugin with overrides to bundle
// react/jsx-runtime instead of externalizing it. This ensures compatibility
// with WordPress < 6.6, which does not register the react-jsx-runtime script.
//
// Returning `false` (not `undefined`) from requestToExternal is critical:
// the plugin only falls through to its defaults when the return value is
// strictly `undefined`, so `false` stops the cascade and keeps the module
// bundled rather than externalized.
plugins.push(
new DependencyExtractionWebpackPlugin( {
requestToExternal( request ) {
if ( request === 'react/jsx-runtime' ) {
return false;
}
},
} )
);
module.exports = {
...defaultConfig,
plugins,
devtool: 'source-map',
entry: {
'wp-console': resolve( 'src/wp-console.js' ),
},
output: {
filename: '[name].js',
path: resolve( 'assets', 'js' ),
chunkFilename: 'chunks/[chunkhash].js',
chunkLoadingGlobal: 'wpConsoleWebpack',
},
};