-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.production.config.js
executable file
·65 lines (60 loc) · 1.79 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
process.env.NODE_ENV = 'production'
var path = require('path')
var webpack = require('webpack')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
function failBuildOnCompilationErrors() {
this.plugin('done', function(stats) {
if (stats.compilation.errors && stats.compilation.errors.length > 0) {
console.error('webpack build failed:')
stats.compilation.errors.forEach(function(error) {
console.error(error.message)
})
process.exit(1)
}
})
}
module.exports = {
devtool: 'source-map',
entry: {
app: path.resolve(__dirname, 'src', 'index.js')
},
output: {
path: path.resolve(__dirname, 'public', 'build'),
filename: 'app.js',
publicPath: '/build/'
},
plugins: [
failBuildOnCompilationErrors,
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new ExtractTextPlugin('style.css'),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
// Move anything imported from node_modules into a vendor bundle
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.js',
minChunks: function(module, count) {
return (
module.resource &&
module.resource.indexOf(path.resolve(__dirname, 'node_modules')) === 0 &&
/\.js$/.test(module.resource)
)
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true,
warnings: false
}
})
],
module: {
loaders: [
{test: /\.js$/, loader: 'babel', exclude: /node_modules/},
{test: /\.css$/, loader: ExtractTextPlugin.extract('style', 'css?-minimize')},
{test: /\.(gif|jpe?g|png|otf|eot|svg|ttf|woff|woff2).*$/, loader: 'file?name=[name].[ext]'}
]
}
}