-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
153 lines (150 loc) · 4.64 KB
/
webpack.config.js
File metadata and controls
153 lines (150 loc) · 4.64 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
var path = require('path');
var webpack = require('webpack');
var htmlWebpackPlugin = require('html-webpack-plugin'); // html模板插件
var CopyWebpackPlugin = require("copy-webpack-plugin");
var HtmlWebpackIncludeAssetsPlugin = require('html-webpack-include-assets-plugin');
var MiniCssExtractPlugin = require("mini-css-extract-plugin"); // 打包css插件
var config = {
entry: {
app: path.resolve(__dirname, './src/App.js'),
},
output: {
path: path.resolve(__dirname, './html'),
filename: '[name].min.js',
chunkFilename: '[id].[name].[chunkhash:8].min.js' //chunk生成的配置
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('dev')
}
}),
new webpack.DllReferencePlugin({
context: __dirname,
/**
* 在这里引入 manifest 文件
*/
manifest: require('./dll/vendor-manifest.json')
}),
new webpack.HotModuleReplacementPlugin(), // 热模块替换插件
new htmlWebpackPlugin({
title: '企业福利管理系统',
filename: './index.html',
favicon: 'favicon.ico',
template: './src/app.html',
hash: true, //为静态资源生成hash值
minify: { //压缩HTML文件
removeComments: true, //移除HTML中的注释
collapseWhitespace: false //删除空白符与换行符
}
}),
new MiniCssExtractPlugin({
filename: "[name].[chunkhash:8].css",
chunkFilename: "[id].[name].[chunkhash:8].css"
}),
new CopyWebpackPlugin([
{
from: "./dll/vendor.dll.js",
to: "dll.js"
}
]),
new HtmlWebpackIncludeAssetsPlugin({
assets: ['dll.js'],
append: false,
}),
],
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
chunks: 'initial',
name: 'vendors'
},
'async-vendors': {
test: /[\\/]node_modules[\\/]/,
minChunks: 2,
chunks: 'async',
name: 'async-vendors'
},
'async-components': {
test: /[\\/]src[\\/]components[\\/]/,
minChunks: 2,
chunks: 'async',
name: 'async-components'
},
}
},
runtimeChunk: { name: 'runtime' }
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
config: {
path: 'postcss.config.js'
}
}
}
]
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
config: {
path: 'postcss.config.js'
}
}
},
{
loader: 'less-loader'
},
],
},
{
test: /\.(png|jpg|woff|eot|ttf|svg)$/,
loader: 'url-loader?limit=2048&name=images/[name].[ext]'
},
{
test: /\.html$/,
loader: 'html-loader',
exclude: /node_modules/
}
]
},
devServer: {
disableHostCheck: true,
port: 8088,
hot: true,
proxy: {
// 开发环境 begin
'/api_dev_adm/': {
target: 'http://kj.lex55.top',
secure: false,
changeOrigin: true,
pathRewrite: { '^/api_dev_adm': '' }
}
}
}
}
module.exports = config;