-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.production.js
83 lines (81 loc) · 2.3 KB
/
webpack.config.production.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
/**
* WEBPACK CONFIG
*
* Notes on config properties:
*
* 'entry'
* Entry point for the bundle.
*
* 'output'
* If you pass an array - the modules are loaded on startup. The last one is exported.
*
* 'resolve'
* Array of file extensions used to resolve modules.
*
* devtool: 'eval-source-map'
* http://www.cnblogs.com/Answer1215/p/4312265.html
* The source map file will only be downloaded if you have source maps enabled
* and your dev tools open.
*
* OccurrenceOrderPlugin
* Assign the module and chunk ids by occurrence count. Ids that are used often
* get lower (shorter) ids. This make ids predictable, reduces to total file size
* and is recommended.
*
* UglifyJsPlugin
* Minimize all JavaScript output of chunks. Loaders are switched into minimizing mode.
* - 'compress'
* Compressor is a tree transformer which reduces the code size by applying
* various optimizations on the AST.
*
* 'NODE_ENV'
* React relies on process.env.NODE_ENV based optimizations.
* If we force it to production, React will get in an optimized manner.
* This will disable some checks (eg. property type checks) and give you a smaller
* build and improved performance.
*
* Note: That JSON.stringify is needed as webpack will perform string replace
* "as is". In this case we'll want to end up with strings as that's what
* various comparisons expect, not just production. Latter would just cause
* an error.
*
* 'babel'
* Babel enables the use of ES6 today by transpiling your ES6 JavaScript into
* equivalent ES5 source that is actually delivered to the end user browser.
*/
const webpack = require('webpack');
const path = require('path');
module.exports = {
entry: './scripts/index',
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/'
},
resolve: {
extensions: ['', '.js']
},
devtool: 'source-map',
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
],
module: {
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel'],
include: path.join(__dirname, 'scripts')
}
]
}
};