forked from tongdun/data4test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
111 lines (104 loc) · 2.8 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 fs = require('fs');
const path = require('path');
const webpack = require('webpack');
function deleteDir(dir) {
var files = [];
if (fs.existsSync(dir)) {
files = fs.readdirSync(dir);
files.forEach(function (file, index) {
var curDir = dir + "/" + file;
if (fs.statSync(curDir).isDirectory()) { // recurse
deleteJS(curDir);
} else { // delete file
fs.unlinkSync(curDir);
}
});
fs.rmdirSync(dir);
}
};
var isDev = false;
if (process.env && process.env.NODE_ENV === 'dev') {
isDev = true;
}
//总是清除之前生成的文件
var distDir = path.join(__dirname, 'web', 'static', 'js');
deleteDir(distDir);
var config = {
entry: {
vendor: ['es6-promise', 'vue', 'vue-router', 'vue-i18n', 'echarts', 'lodash', 'axios', 'moment', 'iview-style', 'iview', 'highlight.js-style', 'highlight.js'],
app: ['./web/ts/main.ts']
},
output: {
filename: '[name].min.js',
path: distDir
},
resolve: {
extensions: ['.ts', '.js', '.vue'],
alias: {
'iview-style': 'iview/dist/styles/iview.css',
'highlight.js-style': 'highlight.js/styles/default.css'
}
},
module: {
rules: [
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
esModule: true
}
},
{
test: /\.ts$/,
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
}
},
{
test: /\.(png|jpg|gif|woff|woff2|svg|eot|ttf)$/,
loader: 'url-loader',
options: {
name: './static/img/[hash].[ext]'
}
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity
})
]
}
if (isDev) {
config.watch = true;
config.devtool = '#cheap-module-eval-source-map';
config.plugins.unshift(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"'
}
})
);
} else {
config.plugins.unshift(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
})
);
config.plugins.unshift(
new webpack.optimize.UglifyJsPlugin({
minimize: true
})
);
//生产模式,删除 go/statik 目录重新生成
deleteDir(path.join(__dirname, 'statik'));
}
module.exports = config;