-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
47 lines (45 loc) · 1.91 KB
/
Copy pathwebpack.config.js
File metadata and controls
47 lines (45 loc) · 1.91 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
/**
* Webpack config for the modern (@wordpress/scripts) build pipeline.
*
* Extends the wp-scripts default config (which includes the DependencyExtractionWebpackPlugin
* that emits the `*.asset.php` manifests) and only overrides the entry + output location so the
* modern host shell builds from `admin/src-modern/` into `admin/build/`.
*
* This runs in parallel to the legacy gulp + rollup pipeline (admin/src -> admin/js); that one
* is untouched and retired later (#43).
*/
const path = require( 'path' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
function requestToExternal( request ) {
if ( request === '@wordpress/interface' ) {
return [ 'wp', 'interface' ];
}
}
module.exports = {
...defaultConfig,
// The repo's legacy `browserslist` file includes "maintained node versions" for the gulp/babel
// pipeline. Webpack would resolve a mixed browser+Node target from it and fail to pick a chunk
// format. The host shell is a browser bundle, so pin a browser target here and leave the legacy
// browserslist untouched.
target: [ 'web', 'es2017' ],
entry: {
index: path.resolve( process.cwd(), 'admin/src-modern', 'index.js' ),
// Editor-only launchers (toolbar/menu/command); needs @wordpress/editor et al.
docs: path.resolve( process.cwd(), 'admin/src-modern/docs', 'index.js' ),
// Editor-agnostic floating window; loadable on ANY admin page (see PHP conditional enqueue).
'docs-window': path.resolve( process.cwd(), 'admin/src-modern/docs', 'window-entry.js' ),
},
output: {
...defaultConfig.output,
path: path.resolve( process.cwd(), 'admin/build' ),
},
plugins: [
...defaultConfig.plugins.filter(
( plugin ) => plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
),
new DependencyExtractionWebpackPlugin( {
requestToExternal,
} ),
],
};