-
Notifications
You must be signed in to change notification settings - Fork 147
/
webpack.production.config.js
45 lines (44 loc) · 1.72 KB
/
webpack.production.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
var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin'); //抽取CSS文件插件
module.exports = {
entry: {
pages: __dirname +'/app/src/router.jsx',
vendors:['react','react-dom','react-router','reflux'] //第三方库和框架
},
output: {
path: __dirname + '/app/dist',
publicPath:'dist/', //事实上,这个配置直接影响了图片的输出路径
filename: 'js/bundle.js'
},
module: {
loaders: [
{ test: /\.css$/, loader: ExtractTextPlugin.extract({fallbackLoader:'style-loader', loader:'css-loader'}) }, //坑:不能用叹号链接,必须写成这种格式
{ test: /\.less$/, loader: ExtractTextPlugin.extract('css-loader!less-loader') },
{ test: /\.js[x]?$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192&name=img/[name].[ext]' },
{ test: /\.(woff|woff2|eot|ttf|svg)(\?.*$|$)/, loader: 'url-loader' }
]
},
resolve: {
extensions: [' ', '.js', '.jsx'],
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({'name':'vendors','filename':'js/vendors.js'}),
new ExtractTextPlugin("css/bundle.css"),
// jquery配置
// new webpack.ProvidePlugin({ $: "jquery" }),
// 压缩配置
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
// 配置环境变量到Production,防止控制台警告
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
]
};