-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
97 lines (93 loc) · 2.84 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
import webpack from 'webpack';
import path from 'path';
import bundleAnalyzer from 'webpack-bundle-analyzer';
import CompressionPlugin from 'compression-webpack-plugin';
import zlib from 'zlib';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default {
mode: (process.env.NODE_ENV === 'production' ? 'production' : 'development'),
entry: path.join(__dirname, 'lib', 'frontend', 'main.js'),
output: {
path: path.join(__dirname, 'build', 'scripts'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
},
{
test: /\.js(x*)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
cacheDirectory: 'babel-cache',
presets: ['@babel/preset-react', '@babel/preset-env'],
plugins: [
['@babel/plugin-proposal-decorators', { "legacy": true }],
'dedent'
],
},
},
{
test: /\.css$/,
use: ['style-loader','css-loader'],
},
{
test: /\.less$/,
use: ['style-loader','css-loader', 'less-loader'],
},
{
test: /\.(ttf|eot|woff|woff2)$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
},
{
test: /\.(png|gif|svg)$/,
loader: 'url-loader',
options: {
name: 'images/[name].[ext]',
},
},
],
},
devtool: 'source-map',
plugins: [
new webpack.ProvidePlugin({
'jQuery': 'jquery',
'$': 'jquery',
'window.jQuery': 'jquery',
'window.$': 'jquery',
}),
new bundleAnalyzer.BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
}),
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}),
new CompressionPlugin({
filename: "[path][base].br",
algorithm: "brotliCompress",
test: /\.(js|css|html|svg)$/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false,
})
],
resolve: {
extensions: ['.js', '.jsx'],
},
};