-
Notifications
You must be signed in to change notification settings - Fork 32
/
webpack.config.js
97 lines (86 loc) · 1.76 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
'use strict'
// 设置环境常量
const [DEV, PRO] = ['development', 'production'];
const NODE_ENV = process.env.NODE_ENV || DEV;
const webpack = require('webpack');
const path = require('path');
module.exports = {
// 入口文件
entry: {
app: './src/app.js'
},
// 输出
output: {
path: __dirname,
publicPath: '/',
filename: 'build.js'
},
// 根据环境开启监听模式
watch: NODE_ENV === DEV,
// 监听参数配置
watchOptions: {
aggregateTimeout: 100
},
// 开发工具
devtool: NODE_ENV === DEV ? 'cheap-inline-module-source-map' : null,
// 解析
resolve: {
alias: {
vue: 'vue/dist/vue.min.js'
}
},
// 模块
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.less/,
loader: 'style-loader!css-loader!less-loader'
},
{
test: /\.(eot|woff2?|svg|ttf|mp3|wav)([\?]?.*)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
},
{
test: /\.(png|jpe?g|gif)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
}
};
// 如果是生产环境
if (NODE_ENV === PRO) {
module.exports.devtool = '#source-map';
module.exports.plugins = (module.exports.plugins || []).concat([
// 定义全局变量
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: `"${PRO}"`
}
}),
// 压缩
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]);
}