-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathwebpack.config.js
88 lines (86 loc) · 2.43 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
/**
* Created by tangjiang on 2017/4/26.
*/
var webpack = require('webpack');
var path = require('path');
var webpackMerge = require('webpack-merge');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var base = {
entry: {
app: './front/app.js',
vendor: 'moment'
},
output: {
path: path.join(__dirname, '/www/dist'),
publicPath: '/dist/',
filename: '[name].[chunkhash].js',
sourceMapFilename: '[name].map'
},
module: {
loaders: [
{
test: /\.vue/,
loaders: 'vue-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
loaders: ['to-string-loader', 'css-loader']
},
{
test: /\.(jpg|png|gif)$/,
loader: 'file-loader'
},
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000'
}
],
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor'] // 指定公共 bundle 的名字。
}),
new HtmlWebpackPlugin({ // 自动生成包含新的打包文件路径的html文件
filename: path.join(__dirname, '/view/home/index_index.html'), // 输出html文件到 thinkjs view(视图)对应的home模块下
template: 'view/home/webpack_template.html'
})
]
};
if (process.env.NODE_ENV === 'production') {
module.exports = webpackMerge(base, {
output: {
filename: '[name].[chunkhash].js',
},
devtool: '#source-map',
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
compress: {
screw_ie8: true,
warnings: false
},
comments: false
})
]
})
} else {
module.exports = webpackMerge(base, {
output: {
filename: '[name].[hash].js'
},
devtool: "cheap-eval-source-map"
})
}