-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.config.js
138 lines (120 loc) · 4.44 KB
/
webpack.prod.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var path = require('path');
var resolve = path.resolve;
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
devtool:false,
entry:{
"index":['./index'],
"vendor":['babel-polyfill','jquery','md5','base64','ttfund','common','requestmodel','routerhelper']
},
output: {
path: path.resolve(__dirname, 'dist'),//打包后的文件存放的地方
filename: '[name]-[hash:5].min.js', //打包后输出文件的文件名
publicPath: "./"
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
comments: false, //去掉注释
compress: {
warnings: false //忽略警告,要不然会有一大堆的黄色字体出现……
}
}),
new webpack.ProvidePlugin({
'Promise': 'es6-promise',
'fetch': 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
"React": 'react',
"ReactDOM": 'react-dom',
"Component": ['react', 'Component'],
"PropTypes": 'prop-types'
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new HtmlWebpackPlugin({
template: __dirname + "/index.tpl.html",
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
},
filename: 'index.html',
//要把script插入到标签里
inject: 'body',
chunks:["vendor","index"]
}),
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
minChunks: Infinity,
})
],
module: {
rules: [
{
test: /\.(less|css)$/,
exclude: /node_modules/,
use:[
'style-loader',
{
loader: 'css-loader?sourceMap',
options: {
minimize: true,
modules: true,
localIdentName: '[name]-[local]-[hash:base64:5]',
importLoaders: 2
}
},
{ loader: 'postcss-loader', options: { sourceMap: true } },
'less-loader?sourceMap'
]
},
{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: { presets:
[
"env",
"babel-preset-stage-0",
"react"
]
}
},
{
test: /\.(gif|jpg|png|woff|eot|ttf|svg)$/,
exclude: /node_modules/,
use: [
{
loader: 'url-loader',
options: {
limit:8192 // 图片小于8k就转化为 base64, 或者单独作为文件
}
}
]
}
]
},
resolve: {
extensions: ['.js','.css','.less'],
modules: ['node_modules','components','views','resources','plugins','libs'],
alias: {
'jquery': resolve(__dirname, 'libs/zepto'),
'md5': resolve(__dirname, 'libs/md5'),
'base64': resolve(__dirname, 'libs/base64'),
'common': resolve(__dirname, 'plugins/common'),
'ttfund': resolve(__dirname, 'plugins/ttfund'),
'requestmodel': resolve(__dirname, 'plugins/requestmodel'),
'nativebridge': resolve(__dirname, 'plugins/nativebridge')
}
},
recordsOutputPath: path.resolve(__dirname, 'dist',"records.json")
};