-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
62 lines (54 loc) · 1.78 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
51
52
53
54
55
56
57
58
59
60
61
62
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const { getWebpackEntryPoints } = require( '@wordpress/scripts/utils/config' );
// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
const CopyPlugin = require( 'copy-webpack-plugin' );
// Utilities.
const path = require( 'path' );
const { globSync } = require( 'glob' );
// Gets all of the block stylesheets, which are enqueued separately and inlined
// into the `<head>` area by WordPress. These should not be bundled together.
const blockStylesheets = () => globSync( './src/scss/blocks/core/*.scss' ).reduce(
( files, filepath ) => {
const name = path.parse( filepath ).name;
files[ `css/blocks/core/${ name }` ] = path.resolve(
process.cwd(),
'src/scss/blocks/core',
`${ name }.scss`
);
return files;
}, {}
);
// Add any a new entry point by extending the webpack config.
module.exports = {
...defaultConfig,
...{
entry: {
...getWebpackEntryPoints(),
...blockStylesheets(),
'js/frontend': path.resolve( process.cwd(), 'src/js', 'frontend.js' ),
'css/frontend': path.resolve( process.cwd(), 'src/scss', 'frontend.scss' ),
},
plugins: [
// Very important! Include WP's plugin config or the
// world will cease to exist as we know it.
...defaultConfig.plugins,
// Removes the empty `.js` files generated by webpack but
// sets it after WP has generated its `*.asset.php` file.
new RemoveEmptyScriptsPlugin( {
stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
} ),
// Copies any assets that don't need to be processed to
// the output folder.
new CopyPlugin( {
patterns: [
{
from: './src/media',
to: './media'
}
]
} )
]
}
};