-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.prod.js
99 lines (92 loc) · 2.49 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
99
'use strict'
/* eslint-disable capitalized-comments */
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 OfflinePlugin = require('offline-plugin')
const base = require('./webpack.base')
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'
}
// base.output.publicPath = '/stuck'
// 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',
minChunks: module => {
return (
module.resource &&
/\.(js|css|es6)$/.test(module.resource) &&
module.resource.indexOf('node_modules') !== -1
)
},
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
}),
// progressive web app
// it uses the publicPath in webpack config
new OfflinePlugin({
relativePaths: false,
AppCache: false,
ServiceWorker: {
events: true,
},
}),
new webpack.EnvironmentPlugin(['TRAVIS_COMMIT'])
)
// 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({
use: [_.cssLoader].concat(loaders),
fallback: 'style-loader',
}),
})
})
// minimize webpack output
base.stats = {
// Add children information
children: false,
// Add chunk information (setting this to `false` allows for a less verbose output)
chunks: false,
// Add built modules information to chunk information
chunkModules: false,
chunkOrigins: false,
modules: false,
}
module.exports = base