-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
112 lines (109 loc) · 4.63 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
112
/*
* @Author: Yoko
* @Date: 2017-06-27 17:27:38
* @Last Modified by: mikey.zhaopeng
* @Last Modified time: 2017-08-29 16:31:03
*/
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
//环境变量配置 .dev / online
var WEBPACK_ENV = process.env.WEBPACK_ENV || 'dev';
console.log("WEBPACK_ENV = ",WEBPACK_ENV);
//获取html-webpack-plugin参数的方法
var getHtmlConfig = function(name,title){
return{
template:'./src/view/'+ name +'.html',
filename:'view/'+ name +'.html',
favicon :'./favicon.ico',
title : title,
inject : true,
hash : true,
chunks :['common',name]
};
};
//webpack config
var config = {
entry: {
'common':['./src/page/common/index.js'],
'index':['./src/page/index/index.js'],
'list':['./src/page/list/index.js'],
'detail':['./src/page/detail/index.js'],
'cart':['./src/page/cart/index.js'],
'order-confirm':['./src/page/order-confirm/index.js'],
'order-list':['./src/page/order-list/index.js'],
'order-detail':['./src/page/order-detail/index.js'],
'payment':['./src/page/payment/index.js'],
'user-login':['./src/page/user-login/index.js'],
'user-register':['./src/page/user-register/index.js'],
'user-pass-reset':['./src/page/user-pass-reset/index.js'],
'user-center':['./src/page/user-center/index.js'],
'user-center-update':['./src/page/user-center-update/index.js'],
'user-pass-update':['./src/page/user-pass-update/index.js'],
'result':['./src/page/result/index.js'],
'about':['./src/page/about/index.js'],
'test':['./src/page/test/index.js']
},
output: {
path : __dirname + '/dist/',
publicPath : 'dev' === WEBPACK_ENV ? '/dist/' : '//s.yokokuok.xin/mmall-fe/dist/',
filename : 'js/[name].js'
},
externals:{
'jquery':'window.jQuery'
},
module:{
loaders:[
// {test:/\.css$/,loader:"style-loader!css-loader"}
{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]'},
{
test:/\.string$/,
loader:'html-loader',
query:{
minimize :true,
removeAttributeQuotes : false
}
}
]
},
resolve:{
alias:{
node_modules : __dirname + '/node_modules',
util : __dirname + '/src/util',
page : __dirname + '/src/page',
service : __dirname + '/src/service',
image : __dirname + '/src/image'
}
},
plugins:[
//独立通用模块到js/base.js
new webpack.optimize.CommonsChunkPlugin({
name:'common',
filename:'js/base.js'
}),
//把css单独打包到文件里
new ExtractTextPlugin("css/[name].css"),
new HtmlWebpackPlugin (getHtmlConfig('index','首页')),
new HtmlWebpackPlugin (getHtmlConfig('list','商品列表页')),
new HtmlWebpackPlugin (getHtmlConfig('detail','商品详情页')),
new HtmlWebpackPlugin (getHtmlConfig('cart','购物车')),
new HtmlWebpackPlugin (getHtmlConfig('order-confirm','订单确认页')),
new HtmlWebpackPlugin (getHtmlConfig('order-list','订单列表')),
new HtmlWebpackPlugin (getHtmlConfig('order-detail','订单详情')),
new HtmlWebpackPlugin (getHtmlConfig('payment','订单支付')),
new HtmlWebpackPlugin (getHtmlConfig('user-login','用户登录')),
new HtmlWebpackPlugin (getHtmlConfig('user-register','用户注册')),
new HtmlWebpackPlugin (getHtmlConfig('user-pass-reset','找回密码')),
new HtmlWebpackPlugin (getHtmlConfig('user-center','个人中心')),
new HtmlWebpackPlugin (getHtmlConfig('user-center-update','修改个人信息')),
new HtmlWebpackPlugin (getHtmlConfig('user-pass-update','修改密码')),
new HtmlWebpackPlugin (getHtmlConfig('result','操作结果')),
new HtmlWebpackPlugin (getHtmlConfig('about','关于嗨皮购')),
new HtmlWebpackPlugin (getHtmlConfig('test','测试页面'))
]
};
if('dev' === WEBPACK_ENV ){
config.entry.common.push('webpack-dev-server/client?http://localhost:8088/');
}
module.exports = config;