-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.js
44 lines (37 loc) · 1.04 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
const webpack = require( 'webpack' );
const glob = require( 'glob' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const path = require( 'path' );
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const includesDir = path.resolve( process.cwd(), 'includes' );
const entries = glob
.sync( '*/*.js', { cwd: includesDir } )
.reduce( ( acc, entry ) => {
const [ folder, name ] = entry.split( '/' );
acc[
`${ folder }/${ path.parse( name ).name }`
] = `./includes/${ entry }`;
return acc;
}, {} );
/** @type {webpack.Configuration} */
const config = {
...defaultConfig,
entry: entries,
output: {
path: includesDir,
filename: ( pathData ) => {
const [ folder, name ] = pathData.chunk.name.split( '/' );
return `${ folder }/dist/${ name }.js`;
},
clean: {
keep: ( asset ) => {
return ! asset.includes( 'dist' );
},
},
},
plugins: defaultConfig.plugins.filter(
( plugin ) => ! ( plugin instanceof CleanWebpackPlugin )
),
};
// Return Configuration
module.exports = config;