-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
80 lines (73 loc) · 2.21 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
/*
* @Author: leobaixinxin
* @Date: 2018-01-18 22:46:36
* @Last Modified by: leobaixinxin
* @Last Modified time: 2018-01-28 10:54:43
*/
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';
console.log(WEBPACK_ENV);
//
var getHtmlConfig = function(name,title){
return {
title:title,
template:"./src/view/"+name+".html",
filename:"view/"+name+".html",
inject:true,
hash:true,
chunks:["vender","base",name],
chunksSortMode:"dependency"
}
}
var config = {
entry:{
'vender':['jquery'],
'base':['./src/page/common/index.js',
'./src/page/common/common.js',
'./src/page/module.js'
],
'index':['./src/page/index/index.js'],
'login':['./src/page/login/index.js']
},
output:{
path:'./dist',
filename:'js/[name].js',
publicPath:'/dist'
},
externals:{
'jquery':'window.jQuery'
},
module:{
loaders:[
{
test: /\.css$/,
// exclude: /node_modules|bootstrap/,
loader: ExtractTextPlugin.extract("style-loader","css-loader"),
},
{
test: /\.(gif|png|jpg|woff|svg|eot|ttf)\??.*$/,
// exclude: /node_modules|bootstrap/,
loader: "url-loader?limit=200&name=resource/[name].[ext]",
}
]
},
plugins:[
//独立通用模块到js文件夹下
new webpack.optimize.CommonsChunkPlugin({
names:['base','vender'],
filename: 'js/[name].js'
}),
// 把css单独打包到文件里
new ExtractTextPlugin("css/[name].css"),
// html模版的处理
new HtmlWebpackPlugin(getHtmlConfig('index','首页')),
new HtmlWebpackPlugin(getHtmlConfig('login','登陆')),
]
};
if('dev' === WEBPACK_ENV){
config.entry.base.push('webpack-dev-server/client?http://localhost:8088/');
}
module.exports = config;