-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
111 lines (109 loc) · 2.84 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
const path = require('path')
const UglifyPlugin = require('uglifyjs-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
// 热更新和实际区分开
const entry = process.env.npm_lifecycle_event === 'start' ? ['webpack-hot-middleware/client.js?reload=true', './src/index.js'] : './src/index.js'
function resolve (dir) {
return path.resolve(__dirname, dir)
}
module.exports = {
entry: {
main: entry
},
output: {
path: path.resolve('D:/github/boke-api/build/www'),
filename: '[name].js'
},
module: {
rules: [
{
test:/\.css$/,
use: ExtractTextPlugin.extract({
use:"css-loader",
fallback:"style-loader",
})
},
{
test: /\.less$/,
loader: 'style-loader!css-loader!less-loader',
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: path.posix.join('static', 'img/[name].[hash:7].[ext]')
}
},
{
test: /(\.jsx|\.js)$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
plugins: [
['import', {libraryName: 'antd', style: true}]
]
}
},
{
test: /\.(html)$/,
loader: 'html-loader',
exclude: /node_modules/
}
]
},
devServer: {
// contentBase: './build',//默认webpack-dev-server会为根文件夹提供本地服务器,如果想为另外一个目录下的文件提供本地服务器,应该在这里设置其所在目录(这里设置到"build"目录)
historyApiFallback: true,
inline: true,
port: 3011,
proxy: {
'/api': {
target: 'http://127.0.0.1:9008/',
changeOrigin: true,
cookieDomainRewrite: {
'*': ''
}
}
}
},
plugins: [
new UglifyPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
minify: {
minifyJS: true
},
template: path.resolve(__dirname, './index.html')
}),
new ExtractTextPlugin({
filename: '[name].min.css',
allChunks: true
}),
new webpack.HotModuleReplacementPlugin()
],
optimization: {
runtimeChunk: {
"name": "manifest"
},
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
priority: 1, //添加权重
chunks: 'initial', //刚开始就要抽离
minChunks: 2 //重复2次使用的时候需要抽离出来
}
}
}
},
resolve: {
extensions: ['.js', '.json', 'css', '.wasm', '.mjs'],
alias: {
'@': resolve('src'),
'common': resolve('src/common')
}
}
}