-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.build.js
More file actions
135 lines (131 loc) · 2.8 KB
/
webpack.build.js
File metadata and controls
135 lines (131 loc) · 2.8 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const WebpackBundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
mode: 'production',
entry: {
app: './src/index.tsx',
},
output: {
path: path.resolve(__dirname, './demo'),
publicPath: '/',
filename: 'index.js',
libraryTarget: 'umd'
},
plugins: [
// 清除
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: path.resolve(__dirname, 'demo')
}),
new HtmlWebpackPlugin ({
filename: 'index.html',
template: 'index.html',
inject: true,
title: "code diff",
minify: {
removeComments: true
}
})
// new WebpackBundleAnalyzer({})
],
module: {
rules: [
{
test: /\.(c)ss$/,
use:[
{
loader: 'style-loader'
},
{
loader: 'css-loader'
}
]
},
{
test: /\.less$/,
use:[
{
loader: 'style-loader'
},
{
loader: 'css-loader'
},
{
loader: 'less-loader'
}
]
},
{
test: /\.(js|jsx)$/,
use: {
loader: 'babel-loader',
}
},
{
test: /\.(ts|tsx)$/,
use: [
// {loader: 'babel-loader'},
{
loader: 'ts-loader',
options: {
// 加快编译速度
transpileOnly: true,
// 指定特定的ts编译配置,为了区分脚本的ts配置
configFile: path.resolve(__dirname, './tsconfig.json')
}
}
],
},
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
alias:{
react: path.resolve('./node_modules/react')
}
},
optimization: {
namedModules: true,
splitChunks: {
chunks: "all",
minSize: 30000,
minChunks: 3,
maxAsyncRequests: 5,
maxInitialRequests: 3,
name: true,
cacheGroups: {
// default: {
// minChunks: 2,
// priority: -20,
// reuseExistingChunk: true,
// },
// vendors: {
// test: /[\\/]node_modules[\\/]/,
// chunks: "initial",
// name: "vendor",
// priority: 10,
// enforce: true,
// },
// commons: {
// name: 'vendors',
// chunks: 'all',
// minChunks: 2,
// maxInitialRequests: 5, // The default limit is too small to showcase the effect
// minSize: 0 // This is example is too small to create commons chunks
// }
}
},
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true, // Must be set to true if using source-maps in production
terserOptions: {
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
}
}),
],
}
}