-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
94 lines (91 loc) · 2.23 KB
/
webpack.config.js
File metadata and controls
94 lines (91 loc) · 2.23 KB
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
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
entry: {
bundle: './src/index.jsx',
'add-bar-builder-buttons': './src/add-bar-builder-buttons.js',
},
externals: {
// Third-party libraries
jquery: 'jQuery',
underscore: '_',
lodash: 'lodash',
react: ['vendor', 'React'],
'react-dom': ['vendor', 'ReactDOM'],
// WordPress libraries
'@wordpress/i18n': ['vendor', 'wp', 'i18n'],
'@wordpress/hooks': ['vendor', 'wp', 'hooks'],
// Divi libraries
'@divi/rest': ['divi', 'rest'],
'@divi/data': ['divi', 'data'],
'@divi/modal': ['divi', 'modal'],
'@divi/icon-library': ['divi', 'iconLibrary'],
'@divi/app-ui': ['divi', 'appUi'],
'@divi/error-boundary': ['divi', 'errorBoundary'],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
compact: false,
presets: [
['@babel/preset-env', {
modules: false,
targets: '> 5%',
}],
'@babel/preset-react',
],
},
}
]
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'sass-loader',
options: {
api: 'modern', // Fix deprecation warning
},
},
],
},
]
},
optimization: {
splitChunks: {
cacheGroups: {
vb: {
type: 'css/mini-extract',
test: /[\\/]style(\.module)?\.(sc|sa|c)ss$/,
chunks: 'all',
enforce: true,
name(_, chunks, cacheGroupKey) {
const chunkName = chunks[0].name;
return `${path.dirname(chunkName)}/${cacheGroupKey}-${path.basename(chunkName)}`;
},
},
default: false,
},
},
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
}),
],
resolve: {
extensions: ['.js', '.jsx'],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build'),
},
};