-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.js
More file actions
52 lines (48 loc) · 1.61 KB
/
Copy pathwebpack.config.js
File metadata and controls
52 lines (48 loc) · 1.61 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
const path = require( 'path' );
const webpack = require( 'webpack' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
/** Plugin-specific asset entry points, merged with wp-scripts block entries. */
const customEntries = {
'demo-plugin-frontend': [
path.resolve( __dirname, 'resources/frontend/js/app.js' ),
path.resolve( __dirname, 'resources/frontend/scss/app.scss' ),
],
'demo-plugin-admin': [
path.resolve( __dirname, 'resources/admin/js/app.js' ),
path.resolve( __dirname, 'resources/admin/scss/app.scss' ),
],
};
/**
* Preserves wp-scripts' auto-discovered block entries while adding custom ones.
*
* With `--experimental-modules`, wp-scripts exports an array of two configs: the
* classic script config and an ESM module config (`experiments.outputModule`) that
* compiles Interactivity API `viewScriptModule`/`view.js` modules. The jQuery provide
* shim and the custom script/style entries belong only to the classic script build, so
* the ESM module config is passed through untouched. Injecting jQuery or the SCSS/admin
* entries there would break the Interactivity API `view.js` module build.
*/
const extendConfig = ( config ) => {
if ( config.experiments?.outputModule ) {
return config;
}
return {
...config,
plugins: [
...config.plugins,
new webpack.ProvidePlugin( {
$: 'jquery',
jQuery: 'jquery',
} ),
],
entry: {
...( typeof config.entry === 'function'
? config.entry()
: config.entry ),
...customEntries,
},
};
};
module.exports = Array.isArray( defaultConfig )
? defaultConfig.map( extendConfig )
: extendConfig( defaultConfig );