-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwebpack.config.js
112 lines (107 loc) · 2.98 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
// Common configuration for both builds
const commonConfig = {
entry: {
// JavaScript files
'js/acf-escaped-html-notice': './assets/src/js/acf-escaped-html-notice.js',
'js/acf-field-group': './assets/src/js/acf-field-group.js',
'js/acf-input': './assets/src/js/acf-input.js',
'js/acf-internal-post-type': './assets/src/js/acf-internal-post-type.js',
'js/acf': './assets/src/js/acf.js',
'js/pro/acf-pro-blocks': './assets/src/js/pro/acf-pro-blocks.js',
'js/pro/acf-pro-field-group': './assets/src/js/pro/acf-pro-field-group.js',
'js/pro/acf-pro-input': './assets/src/js/pro/acf-pro-input.js',
'js/pro/acf-pro-ui-options-page': './assets/src/js/pro/acf-pro-ui-options-page.js',
// CSS files
'css/acf-dark': './assets/src/sass/acf-dark.scss',
'css/acf-field-group': './assets/src/sass/acf-field-group.scss',
'css/acf-global': './assets/src/sass/acf-global.scss',
'css/acf-input': './assets/src/sass/acf-input.scss',
'css/pro/acf-pro-field-group': './assets/src/sass/pro/acf-pro-field-group.scss',
'css/pro/acf-pro-input': './assets/src/sass/pro/acf-pro-input.scss',
},
output: {
path: path.resolve(__dirname, 'assets/build/'),
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react']
}
},
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader, // Extract CSS into separate files.
{
loader: 'css-loader',
options: {
url: false, // Don't resolve URLs.
},
},
'sass-loader',
],
}
],
},
};
// Unminified build
const unminifiedConfig = {
...commonConfig,
mode: 'development',
output: {
...commonConfig.output,
filename: '[name].js', // Unminified output
},
devtool: 'source-map',
optimization: {
minimize: false, // No minification for this config
},
plugins: [
new FixStyleOnlyEntriesPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css', // Output CSS as .css
}),
],
};
// Minified build
const minifiedConfig = {
...commonConfig,
mode: 'production',
output: {
...commonConfig.output,
filename: '[name].min.js', // Minified output
},
optimization: {
minimize: true, // Enable minification
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false, // Remove comments
},
},
extractComments: false,
}),
new CssMinimizerPlugin(), // Minify CSS
],
},
plugins: [
new FixStyleOnlyEntriesPlugin(),
new MiniCssExtractPlugin({
filename: '[name].min.css', // Changed to output .min.css files
}),
],
};
// Export both configurations
module.exports = [unminifiedConfig, minifiedConfig];