-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathwebpack.prod.js
67 lines (62 loc) · 1.72 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
'use strict'
process.env.NODE_ENV = 'production'
const exec = require('child_process').execSync
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const ProgressPlugin = require('webpack/lib/ProgressPlugin')
const base = require('./webpack.base')
const pkg = require('../package')
const _ = require('./utils')
const config = require('./config')
if (config.electron) {
// remove dist folder in electron mode
exec('rm -rf app/assets/')
} else {
// remove dist folder in web app mode
exec('rm -rf dist/')
// use source-map in web app mode
base.devtool = 'source-map'
}
// a white list to add dependencies to vendor chunk
base.entry.vendor = config.vendor
// use hash filename to support long-term caching
base.output.filename = '[name].[chunkhash:8].js'
// add webpack plugins
base.plugins.push(
new ProgressPlugin(),
new ExtractTextPlugin('styles.[contenthash:8].css'),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
},
output: {
comments: false
}
}),
// extract vendor chunks
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.[chunkhash:8].js'
})
)
// extract css in standalone css files
_.cssProcessors.forEach(processor => {
let loaders
if (processor.loader === '') {
loaders = ['postcss-loader']
} else {
loaders = ['postcss-loader', processor.loader]
}
base.module.loaders.push({
test: processor.test,
loader: ExtractTextPlugin.extract({
loader: [_.cssLoader].concat(loaders,
fallbackLoader: 'style-loader'
})
})
})
module.exports = base