-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.prod.js
84 lines (78 loc) · 2.24 KB
/
webpack.config.prod.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 ExtractTextPlugin = require("extract-text-webpack-plugin")
var CleanWebpackPlugin = require("clean-webpack-plugin")
var proxy = require("http-proxy-middleware")
var CopyWebpackPlugin = require("copy-webpack-plugin")
module.exports={
entry:"./src/app.js",
output:{
path:__dirname+"/dist",
filename:"index_[hash].js"
},
plugins:[//因为是引入的第三方差插件,所以需要在plugins数组中配置
new htmlWebpackPlugin({
template:'./src/index.html', //数据源
filename:'index.html' //生成的文件名称
}),
new ExtractTextPlugin("styles."+Math.random().toString().substring(2)+".css",
{allChunks:true} //片段
),
new webpack.DefinePlugin({
NODE_ENV : JSON.stringify("production")
}),
new webpack.optimize.UglifyJsPlugin({ //生产环境下移出所有的log日志
exclude: /node_modules/,
compress: {
warnings: false,
drop_debugger: true,
drop_console: true
}
}),
new webpack.ProvidePlugin({ //全局配置jquery
$: 'jquery',
jQuery: 'jquery'
}),
new CopyWebpackPlugin([{
from:__dirname+"/src/assets",
to:__dirname+"/dist/assets"
}])
],
module:{
loaders:[
{test: /\.(png|jpg|jpeg|gif)$/, loader: 'file-loader?name=images/[hash].[ext]'},
{test: /\.(svg|woff|woff2|ttf|eot)$/, loader: 'file-loader?name=fonts/[hash].[ext]'},
{test:/\.css$/,loader:'style-loader!css-loader'},
{
test:/\.scss$/,
loader:ExtractTextPlugin.extract({
fallback:"style-loader",
use:'css-loader?modules&localIdentName=[name]__[local]--[hash:base64:5]!sass-loader'
})
},
{//编译jsx
test:/\.js$/,
loader:'babel-loader',
options:{
"presets":['es2015','react','stage-1'],
"plugins": [
["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }], // `style: true` 会加载 less 文件
[
"transform-runtime",
{
"helpers": false,
"polyfill": false,
"regenerator": true,
"moduleName": "babel-runtime"
}
]
]
},
exclude:/node_modules/
}
]
}
}