-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
48 lines (46 loc) · 1.41 KB
/
Copy pathwebpack.config.js
File metadata and controls
48 lines (46 loc) · 1.41 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
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const path = require( 'path' );
const DependencyExtractionPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
// Modules we bundle ourselves (React 19 vs WP's React 18).
const BUNDLED_MODULES = new Set( [
'react',
'react-dom',
'react/jsx-runtime',
'react-dom/client',
] );
module.exports = {
...defaultConfig,
entry: {
'editor/index': path.resolve( __dirname, 'src/editor/index.tsx' ),
},
output: {
...defaultConfig.output,
path: path.resolve( __dirname, 'build' ),
},
// Replace the WP dependency extraction plugin with one that
// does NOT externalize React — we bundle React 19 because
// @portabletext/editor requires it and WP 7 ships React 18.
plugins: [
...( defaultConfig.plugins || [] ).filter(
( plugin ) => plugin.constructor.name !== 'DependencyExtractionWebpackPlugin',
),
new DependencyExtractionPlugin( {
// Return false to prevent externalization of React modules.
requestToExternal( request ) {
if ( BUNDLED_MODULES.has( request ) ) {
// Return an empty array to signal "not external" without
// cascading to defaults.
return false;
}
// Return undefined to cascade to defaults for everything else.
return undefined;
},
requestToHandle( request ) {
if ( BUNDLED_MODULES.has( request ) ) {
return false;
}
return undefined;
},
} ),
],
};