-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
84 lines (78 loc) · 2.24 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
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var version = updateVersion();
var serverFlag = false;//open wepack-server flag
var HOST = '.';
var env = process.env.NODE_ENV;
var lib = './lib/';
var src = './src/';
var entryArr = [src + 'main.js'];
var plugins = [
new webpack.optimize.DedupePlugin(),
new HtmlWebpackPlugin({
template : src + 'index.html',
filename : '../index.html'
})
];
var entryObj = {
'entry': entryArr
};
//if use webpack-dev-server
if (serverFlag) {
HOST = 'http://localhost:8080';
}
if (env != 'development') {
plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}));
if (env == 'production') {
HOST = '.';
}
} else {
[].push.apply(entryArr, ['webpack-dev-server/client?http://0.0.0.0:8080', 'webpack/hot/only-dev-server']);
plugins.push(new webpack.HotModuleReplacementPlugin());
}
var dest = HOST + '/dist/';
function updateVersion () {
var date = new Date;
var version = date.getFullYear() + '' + (date.getMonth() + 1) + date.getDate();
var hash = ~~(Math.random() * 1001);
return version + hash;
};
module.exports = {
//页面入口
entry: entryObj,
//出口文件输出配置
output: {
path: dest, //js位置
publicPath: dest, //web打包的资源地址
filename: 'bundle.js?v=' + version
},
// devtool: '',//'#source-map',//source map 支持
watchOptions: [lib + '**.js', src + '**.js', src + '*/**.js', src + '**.css'], //监控脚本
plugins: plugins,
//加载器
module: {
loaders: [{
test: /\.css$/,
loader: "style-loader!css-loader"
}, {
test: /\.html$/,
loader: "html-loader"
}, {
test: /\.tpl$/,
loader: "html-loader"
}, {
test: /.*\.(png|jpg|jpe?g|ico|gif|svg)$/i,
loaders: [
'image-webpack?{progressive:true, optimizationLevel: 3, interlaced: false, pngquant:{quality: "65-90", speed: 4}}',
'url-loader?limit=8192&name=images/[hash:8].[name].[ext]'
]
}]
},
resolve: {
extensions: ['', '.js']
}
};