-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.example.js
79 lines (77 loc) · 2.45 KB
/
webpack.config.example.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
const path = require('path')
const SimpleWebpackHTMLEntrypoint = require('simple-webpack-html-entrypoint')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
module.exports = {
mode: 'development',
devtool: 'inline-source-map',
devServer: {
open: true,
contentBase: path.join(__dirname, 'build','dist'), // boolean | string | array, static file location
compress: true, // enable gzip compression
historyApiFallback: true, // true for index.html upon 404, object for multiple paths
hot: true, // hot module replacement. Depends on HotModuleReplacementPlugin
https: false, // true for self-signed, object for cert authority
noInfo: true // only errors & warns on hot reload
},
entry: {
index: './src/example/index.ts',
},
output: {
path: path.join(__dirname, 'build', 'dist'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: ['babel-loader', 'ts-loader']
},
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
}
]
},
optimization: {
splitChunks: {
chunks: 'all',
minSize: 0,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
name: true,
cacheGroups: {
default: {
name: 'common',
chunks: 'all',
minSize: 0,
minChunks: 2 //模块被引用2次以上的才抽离
},
vendors: {
name: 'vendors',
test: /[\\/]node_modules[\\/]/,
priority: 1,
},
}
}
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
'@c': path.resolve(__dirname, './src/components'),
'@d': path.resolve(__dirname, './src/def'),
'@s': path.resolve(__dirname, './src/shortcut'),
'@src': path.resolve(__dirname, './src'),
}
},
plugins: [
new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: 'static',
reportFilename: 'bundle-analyzer-report.html'
}),
new SimpleWebpackHTMLEntrypoint()
]
}