-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
96 lines (93 loc) · 2.21 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const webpackMerge = require( 'webpack-merge' );
const defaultConfig = require( './node_modules/@wordpress/scripts/config/webpack.config.js' );
const path = require( 'path' );
const postcssPresetEnv = require( 'postcss-preset-env' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const IgnoreEmitPlugin = require( 'ignore-emit-webpack-plugin' );
const production = process.env.NODE_ENV === '';
/**
* Using webpackMerge.strategy to merge our config with the wp-scripts base config.
*
* strategy was used to ensure we overwrite the entry value entirely.
*/
const config = webpackMerge.strategy(
{
entry: 'replace',
},
)( {}, defaultConfig, {
// Maps our buildList into a new object of { key: build.entry }.
entry: {
'block-editor': path.resolve( process.cwd(), 'src', 'index.js' ),
'block-styles': path.resolve( process.cwd(), 'src', 'style.scss' ),
'block-editor-styles': path.resolve( process.cwd(), 'src', 'editor.scss' ),
},
optimization: {
splitChunks: {
cacheGroups: {
editor: {
name: 'block-editor-styles',
test: /editor\.(sc|sa|c)ss$/,
chunks: 'all',
enforce: true,
},
style: {
name: 'block-styles',
test: /style\.(sc|sa|c)ss$/,
chunks: 'all',
enforce: true,
},
default: false,
},
},
},
module: {
rules: [
{
test: /\.(sc|sa|c)ss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: ! production,
},
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [
postcssPresetEnv( {
stage: 3,
features: {
'custom-media-queries': {
preserve: false,
},
'custom-properties': {
preserve: true,
},
'nesting-rules': true,
},
} ),
],
},
},
{
loader: 'sass-loader',
options: {
sourceMap: ! production,
},
},
],
},
],
},
plugins: [
new MiniCssExtractPlugin( {
filename: '[name].css',
} ),
new IgnoreEmitPlugin( [ /-styles.js$/, /-styles.min.js$/, /-styles.js.map$/ ]),
],
} );
module.exports = config;