-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
97 lines (93 loc) · 3 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
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
const path = require('path');
const fs = require('fs');
const swcConfig = JSON.parse(fs.readFileSync('./.swcrc'));
const MiniCssExtractPluginCleanup = require('./util/MiniCssExtractPluginCleanup');
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
context: path.join(__dirname, '/src/main/resources/assets/admin/common'),
entry: {
'js/lib': './js/lib.ts',
'styles/lib': './styles/main.less',
'styles/lib.lite': './styles/main.lite.less',
},
output: {
path: path.join(__dirname, '/build/resources/main/assets/admin/common'),
filename: './[name].js',
assetModuleFilename: './[file]'
},
resolve: {
extensions: ['.ts', '.js', '.less', '.css']
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'swc-loader',
options: {
...swcConfig,
sourceMaps: isProd ? false : 'inline',
inlineSourcesContent: !isProd,
},
},
],
},
{
test: /\.less$/,
use: [
{loader: MiniCssExtractPlugin.loader, options: {publicPath: '../'}},
{loader: 'css-loader', options: {sourceMap: !isProd, importLoaders: 1}},
{loader: 'postcss-loader', options: {sourceMap: !isProd}},
{loader: 'less-loader', options: {sourceMap: !isProd}},
]
},
{
test: /^((?!icomoon|opensans).)*\.(svg|png|jpg|gif)$/,
type: 'asset/resource',
generator: {
filename: 'images/[base]'
}
}
]
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true
}
})
]
},
plugins: [
new ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: './styles/[id].css'
}),
new MiniCssExtractPluginCleanup([/main\.(lite\.)?js(\.map)?$/]),
new CircularDependencyPlugin({
exclude: /a\.js|node_modules/,
failOnError: true
}),
],
mode: isProd ? 'production' : 'development',
devtool: isProd ? false : 'source-map',
performance: {
hints: false,
},
stats: {
assets: false,
modules: false,
}
};