-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
113 lines (111 loc) · 3.38 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
113
const pkg = require('./package.json')
const path = require('path')
const Html = require('html-webpack-plugin')
const Copy = require("copy-webpack-plugin")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin")
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const devMode = process.env.NODE_ENV === 'development'
module.exports = {
// devtool: 'cheap-module-source-map',
entry: {
index: './src/app.tsx',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
library: { type: 'umd' },
clean: true,
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
alias: {
'@image': path.resolve(__dirname, 'src/images/'),
'@src': path.resolve(__dirname, 'src/'),
},
},
devServer: {
static: [{
directory: path.join(__dirname + '/dist'),
watch: true,
}],
hot: true,
open: true,
port: 8888,
},
module: {
rules: [{
test: /\.ts(x?)$/,
use: [{
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', {
useBuiltIns: 'usage', corejs: { version: '3.19' },
targets: pkg.browserslist,
debug: false,
}],],
},
}, {
loader: 'ts-loader',
}],
}, {
test: /\.less$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'less-loader',
],
}, {
test: /\.css$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
],
}, {
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
generator: devMode ? {} : {
filename: (path) => {
return path.filename.replace('src', 'static')
}
},
},]
},
optimization: {
minimizer: [
'...',
new CssMinimizerPlugin(),
],
splitChunks: {
cacheGroups: {
bennowu: {
test: /[\\/]node_modules[\\/]@bennowu/,
name: 'bennowu',
priority: 100,
chunks: 'all',
},
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
priority: 0,
chunks: 'all',
},
},
},
},
plugins: [
// new BundleAnalyzerPlugin(),
new Html({
template: path.resolve(__dirname, './src/index.html'),
}),
// todo css 的大小优化
new Copy({
patterns: [
{ from: 'src/static', to: 'static' },
{ from: path.resolve(__dirname, 'node_modules', 'antd', 'dist', 'antd.min.css'), to: 'static' },
{ from: path.resolve(__dirname, 'node_modules', 'antd', 'dist', 'antd.dark.min.css'), to: 'static' },
]
}),
new MiniCssExtractPlugin(),
],
}