-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.base.js
74 lines (72 loc) · 1.98 KB
/
webpack.config.base.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
//@ts-check
import { resolve } from 'path';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import terser from 'terser-webpack-plugin';
import WebpackBarPlugin from 'webpackbar';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
/**
* @param {Record<string,string|boolean>} env
* @param {{ mode: 'production' | 'development' | 'none' | undefined; }} argv
* @returns { Promise<import('webpack').Configuration> }
*/
export default async function (env, argv) {
const mode = argv.mode || 'development';
return {
mode,
devtool: argv.mode === 'development' && 'eval-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader'
},
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: { postcssOptions: { plugins: [['postcss-preset-env']] } }
}
]
},
{
test: /.(woff2?|eot|ttf|otf)|(webp|svg)$/,
type: 'asset/inline'
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.css', '.webp', '.svg'],
alias: {
'luogu-api': resolve('luogu-api-docs', 'luogu-api'),
assets: resolve('assets')
}
},
optimization:
mode == 'production'
? {
minimize: true,
usedExports: true,
innerGraph: true,
minimizer: [
new terser({
parallel: true,
terserOptions: {
format: { comments: false }
},
extractComments: false
}),
new CssMinimizerPlugin()
]
}
: {},
plugins: [
new WebpackBarPlugin(),
...(env.analyze ? [new BundleAnalyzerPlugin()] : []),
new MiniCssExtractPlugin()
]
};
}