-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwebpack.prod.js
98 lines (87 loc) · 2.57 KB
/
webpack.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
const path = require('path')
const webpack = require('webpack')
const BabiliPlugin = require("babili-webpack-plugin")
const config = require('./webpack.base')
const buildPath = path.join(__dirname, 'build')
// Merge with base configuration
//-------------------------------
Object.assign(config, {
cache: false,
devtool: 'source-map',
entry: {
bundle: path.join(__dirname, 'src/config/client.js')
},
output: {
path: buildPath,
publicPath: '/build/'
}
})
// Support for old browsers
//------------------------------------
config.module.loaders.forEach(loader => {
if (loader.loader === 'babel-loader') {
loader.query.plugins = loader.query.plugins.concat([
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
"transform-es2015-block-scoping",
"transform-es2015-classes",
"transform-es2015-computed-properties",
"transform-es2015-destructuring",
"transform-es2015-literals",
"transform-es2015-parameters",
"transform-es2015-shorthand-properties",
"transform-es2015-spread",
"transform-es2015-template-literals",
["fast-async"]
])
}
})
console.info('Environment: Production')
// Production plugins
//-------------------------------
config.plugins = config.plugins.concat([
new webpack.optimize.OccurrenceOrderPlugin(),
new BabiliPlugin({ evaluate: false }, { comments: false }),
new webpack.EnvironmentPlugin({
'DEV': false,
'BROWSER': true,
'NODE_ENV': JSON.stringify('production'),
})
])
// Sanity checks
//-------------------------------
if (config.devtool === 'eval') {
throw new Error('Using "eval" source-maps may break the build')
}
// Compile everything for PROD
//-------------------------------
const compiler = webpack(config)
compiler.run(function(err, stats) {
if (err) throw err
// Output stats
console.log(stats.toString({
colors: true,
hash: false,
version: false,
chunks: false,
modules: false,
children: false,
chunkModules: false
}))
// Write a stats.json for the webpack bundle visualizer
//writeWebpackStats(stats)
if (stats.hasErrors()) {
console.error(stats.compilation.errors.toString())
}
console.info('Finished compiling')
})
/**
* Writes a stats.json for the webpack bundle visualizer
* URL: https://chrisbateman.github.io/webpack-visualizer/
* @param stats
*/
function writeWebpackStats(stats) {
const location = path.resolve(config.output.path, 'stats.json')
require('fs').writeFileSync(location, JSON.stringify(stats.toJson()))
console.info(`Wrote stats.json to ${location}`)
}