-
Notifications
You must be signed in to change notification settings - Fork 7
/
config-overrides.js
65 lines (55 loc) 路 1.5 KB
/
config-overrides.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
'use strict'
const webpack = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin
const manifestJson = require('./public/manifest.json')
const StringReplacePlugin = require('string-replace-webpack-plugin')
const signale = require('signale')
module.exports = (config, env) => {
if (env === 'production') {
config = rewireUglifyJS(config, env)
} else {
config = rewireBundleAnalyzer(config, env)
}
config = rewireStringReplace(config, env)
return config
}
function rewireUglifyJS(config, env) {
config.plugins.unshift(
new UglifyJsPlugin({
sourceMap: true,
uglifyOptions: {
compress: {
drop_console: true,
unused: true,
dead_code: true,
},
},
}),
)
return config
}
function rewireBundleAnalyzer(config, env) {
config.plugins.push(new BundleAnalyzerPlugin())
return config
}
function rewireStringReplace(config, env) {
const version = env === 'production' ? manifestJson.version : '0.0.0'
signale.info(`[INFO] octodirect version : ${version}`)
config.module.rules.push({
test: /(\.tsx)$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /#__VERSION__#/gi,
replacement: function(match, p1, offset, string) {
return version
},
},
],
}),
})
config.plugins.push(new StringReplacePlugin())
return config
}