-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
109 lines (107 loc) · 2.72 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
var path = require('path');
var webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = (env = {}) =>{
console.log(`------------------- ${env.Generative?'生产':'开发'}环境 -------------------`);
var plugins = (module.exports.plugins || []).concat([
new CleanWebpackPlugin(['dist']),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
if(!env.Generative){
plugins = [];
}
plugins.push(new CopyWebpackPlugin([{
from: 'static',
to: 'static'
}]));
plugins.push(new HtmlWebpackPlugin({template: 'index.html'}));
return {
entry: './src/main.js',//入口
output: {
path: path.resolve(__dirname, './dist'),//输出结果
// publicPath: evn.production ? './' : '/', //文件路径
filename: '[name].js',
chunkFilename: '[id].chunk.js'
},
module: {
rules: [
// 使用vue-loader 加载 .vue 结尾的文件
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
}
// other vue-loader options go here
}
},
// 使用babel 加载 .js 结尾的文件
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
// 加载图标
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
},
//加载css
{
test: /\.css$/,
loader: "style-loader!css-loader",
exclude: /node_modules/
},
{
test: /\.scss$/,
loader: "style-loader!css-loader!sass-loader!"
},
{
test: /\.html$/,
loader: 'html-loader',
options: {
minimize: false
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
},
devServer: {
inline: true, //检测文件变化,实时构建并刷新浏览器
port: "8000",
proxy: {
'/api': {
target: 'http://127.0.0.1:3008/',
pathRewrite: {
"^/api": ""
},
secure: false
},
},
//404 页面返回 index.html
historyApiFallback: true,
},
performance: {
hints: false
},
plugins:plugins,
devtool: '#eval-source-map'//开发模式下更方便定位错误
}
}