forked from Purdue/purdue-blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
71 lines (70 loc) · 1.95 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
63
64
65
66
67
68
69
70
71
const path = require( 'path' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const IgnoreEmitPlugin = require( 'ignore-emit-webpack-plugin' );
// include the clean webpack plugins
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const production = 'development' !== process.env.NODE_ENV;
module.exports = {
...defaultConfig,
entry: {
block: path.resolve( __dirname, 'src', 'block.js' ),
frontend: path.resolve( __dirname, 'src', 'frontend.js' ),
editor: path.resolve( __dirname, 'src', 'editor.scss' ),
style: path.resolve( __dirname, 'src', 'style.scss' ),
},
output: {
filename: '[name].[hash].js',
path: path.resolve( __dirname, 'build' ),
},
module: {
// ...defaultConfig.module,
rules: [
...defaultConfig.module.rules,
{ test: /\.(woff|woff2|eot|ttf|otf)$/,
loader: 'file-loader',
options: {
outputPath: '../fonts',
}
}
],
},
optimization: {
...defaultConfig.optimization,
splitChunks: {
cacheGroups: {
default: false,
editor: {
chunks: 'all',
enforce: true,
name: 'editor',
test: /editor\.s[ac]ss$/i,
},
style: {
chunks: 'all',
enforce: true,
name: 'style',
test: /style\.s[ac]ss$/i,
},
},
},
},
plugins: [
...defaultConfig.plugins,
new IgnoreEmitPlugin( [ 'editor.css', 'style.css', /^editor[a-zA-Z0-9_.-]*js$/, /^style[a-zA-Z0-9_.-]*js$/] ),
new MiniCssExtractPlugin( {
filename: '[name].[hash].css',
} ),
// clean out build directories on each build
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['./build/js/*','./build/css/*']
})
],
performance: {
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
};
if ( production ) {
module.exports.devtool = false;
}