-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
70 lines (68 loc) · 2.04 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
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var WEBPACK_ENV = process.env.WEBPACK_ENV || 'dev';
var getHtmlConfig = function (name) {
return {
template: "./src/view/"+name+".html",
filename: "view/"+name+".html",
inject: true,
hash: true,
chunks: ['common',name]
}
};
var config = {
entry: {
'common': ['./src/page/common/index.js'],
'index': ['./src/page/index/index.js'],
'login': ['./src/page/login/index.js']
},
output: {
path: './dist',
publicPath: '/dist',
filename: 'js/[name].js'
},
externals: {
jquery: 'window.jQuery'
},
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
},
{
test: /\.(gif|png|jpg|woff|svg|eot|ttf)\??.*$/,
loader: 'url-loader?limit=100&name=resource/[name].[ext]'
}
]
},
plugins: [
/*注意这里, 这两个地方用来配置common.js模块单独打包的*/
new webpack.optimize.CommonsChunkPlugin({
name: "common",
filename: "js/base.js"
}),
new ExtractTextPlugin("css/[name].css"),
/*new HtmlWebpackPlugin({
template: "./src/view/index.html",
filename: "view/index.html",
inject: true,
hash: true,
chunks: ['common','index']
}),
new HtmlWebpackPlugin({
template: "./src/view/login.html",
filename: "view/login.html",
inject: true,
hash: true,
chunks: ['common','login']
})*/
new HtmlWebpackPlugin(getHtmlConfig('index')),
new HtmlWebpackPlugin(getHtmlConfig('login'))
]
};
if ('dev' === WEBPACK_ENV) {
config.entry.common.push('webpack-dev-server/client?http://localhost:8088/')
}
module.exports = config;