-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.prod.js
103 lines (102 loc) · 3.46 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var webpack = require('webpack'),
ExtractTextPlugin = require('extract-text-webpack-plugin'), //抽取CSS文件插件
autoprefixer = require('autoprefixer'),
HtmlWebpackPlugin = require('html-webpack-plugin'), //抽取html
path = require('path')
module.exports = {
context: path.join(__dirname, './src'), //上下文,下面'./index.js'的当前目录就是src目录
entry: {
app: './index.js', //将src/index.js文件打包输出到index.html文件的app.js
lib: [ //将数组中的几个依赖项打包输出到index.html的lib.js
'react',
'react-dom',
'react-redux',
'react-router',
'react-router-redux',
'redux'
]
},
output: {
path: path.join(__dirname, './dist'), //编译打包好的文件要放到的目录
filename: '[name].[hash:5].js', //打包压缩后的文件的名字,这里有app.js和lib.js
publicPath: '/' //todo:http://localhost/
},
module: {
loaders: [
{
test: /\.less$/,
exclude: path.resolve(__dirname, './node_modules'),
loader: ExtractTextPlugin.extract('style-loader', 'css-loader?modules&minimize&camelCase&importLoaders=1&localIdentName=[local]__[h' +
'ash:base64:5]!postcss-loader!less-loader')
}, {
test: /\.css$/,
exclude: path.resolve(__dirname, './node_modules'),
loader: ExtractTextPlugin.extract('style-loader', 'css-loader?modules&minimize&camelCase&importLoaders=1&localIdentName=[local]__[h' +
'ash:base64:5]!postcss-loader')
}, {
test: /\.less$/,
include: path.resolve(__dirname, './node_modules'),
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader!less-loader')
}, {
test: /\.css$/,
include: path.resolve(__dirname, './node_modules'),
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader')
}, {
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loaders: ['react-hot', 'babel-loader']
}, {
test: /\.json$/,
loader: 'json-loader'
},
// { test: /\.(png|jpg)$/, loader:
// 'url-loader?limit=8192&name=[name]_[hash:5].[ext]' }
{
test: /\.(png|jpg|woff|woff2|eot|ttf)$/,
loader: 'url-loader?limit=60000&name=[name]_[hash:5].[ext]'
}
]
},
resolve: {
extensions: [
'', '.js', '.jsx'
],
alias: {
'styles': __dirname + '/src/styles',
'imgs': __dirname + '/src/imgs/',
'fonts': __dirname + '/src/fonts/'
}
},
postcss: [autoprefixer({
browsers: [
'Android >= 4',
'iOS > 6',
'last 10 Chrome versions',
'last 4 Firefox versions',
'Safari >= 6',
'ie > 8'
]
})],
plugins: [
new webpack
.optimize
.CommonsChunkPlugin('lib', 'lib.[hash:5].js'),
new ExtractTextPlugin("[name].[hash:5].css"), //
new webpack.DefinePlugin({
// 'process.env': { NODE_ENV: JSON.stringify(process.env.NODE_ENV ||
// 'development') }
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}),
new webpack
.optimize
.OccurrenceOrderPlugin(),
new webpack
.optimize
.DedupePlugin(),
new webpack
.optimize
.UglifyJsPlugin({sourceMap: false, unused: true, dead_code: true, warnings: false}),
new HtmlWebpackPlugin({minify: {}, template: './index.html'}), //minify:压缩HTML文件
new webpack.ProvidePlugin({"_": "lodash"})
]
}