-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
50 lines (45 loc) · 1.35 KB
/
webpack.config.js
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
/**
* Custom webpack config for multiple blocks.
*/
const { basename, dirname, parse } = require( 'path' );
const glob = require( 'fast-glob' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
module.exports = {
...defaultConfig,
entry() {
// Get the default entries.
const entries = (typeof defaultConfig.entry === 'function') ? defaultConfig.entry() : defaultConfig.entry;
// Add entries dynamically for any scripts in the root of the src folder.
const scripts = glob.sync( './src/*.js' );
scripts.forEach( ( script ) => {
const name = basename( script, '.js' );
entries[ name ] = script;
} );
return entries;
},
optimization: {
...( defaultConfig?.optimization || {} ),
splitChunks: {
...( defaultConfig?.optimization?.splitChunks || {} ),
cacheGroups: {
...( defaultConfig?.optimization?.splitChunks?.cacheGroups ||
{} ),
// Output individual CSS files with original filename.
style: {
type: 'css/mini-extract',
test: /\.(sc|sa|c)ss$/,
chunks: 'all',
enforce: true,
name( module, chunks, cacheGroupKey ) {
const chunkName = dirname( chunks[ 0 ].name );
const fileName = parse( module._identifier ).name;
return `${ dirname( chunkName ) }/${ basename(
chunkName
) }/${ fileName }`;
},
},
default: false,
},
},
},
};