-
Notifications
You must be signed in to change notification settings - Fork 4
/
config-overrides.js
112 lines (105 loc) · 3.46 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
const os = require('os')
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
const {
override,
addWebpackExternals,
addWebpackAlias,
addWebpackPlugin
} = require('customize-cra')
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
function findWebpackPlugin (plugins, pluginName) {
return plugins.find(plugin => plugin.constructor.name === pluginName)
}
function overrideProcessEnv (value) {
return config => {
const plugin = findWebpackPlugin(config.plugins, 'DefinePlugin')
const processEnv = plugin.definitions['process.env'] || {}
plugin.definitions['process.env'] = {
...processEnv,
...value
}
return config
}
}
function turnOffMangle () {
return config => {
config.optimization.minimizer = config.optimization.minimizer.map(
minimizer => {
if (minimizer instanceof TerserPlugin) {
minimizer.options.terserOptions.mangle = false
}
return minimizer
}
)
return config
}
}
function addWasmLoader (options) {
return config => {
config.resolve.extensions.push('.wasm')
config.module.rules.forEach(rule => {
(rule.oneOf || []).forEach(oneOf => {
if (oneOf.loader && oneOf.loader.indexOf('file-loader') >= 0) {
oneOf.exclude.push(/\.wasm$/);
}
})
})
return config
}
}
const overrides = [
addWebpackAlias({
crypto: 'crypto-browserify',
'@solidity-parser/parser': '@solidity-parser/parser/dist/index.cjs.js',
'@': path.resolve(__dirname, 'src/lib'),
'@obsidians/welcome': `@obsidians/${process.env.BUILD}-welcome`,
'@obsidians/header': `@obsidians/${process.env.BUILD}-header`,
'@obsidians/bottombar': `@obsidians/${process.env.BUILD}-bottombar`,
'@obsidians/compiler': `@obsidians/${process.env.PROJECT}-compiler`,
'@obsidians/project': `@obsidians/${process.env.BUILD}-project`,
'@obsidians/contract': `@obsidians/${process.env.BUILD}-contract`,
'@obsidians/explorer': `@obsidians/${process.env.BUILD}-explorer`,
'@obsidians/sdk': `@obsidians/${process.env.PROJECT}-sdk`,
'@obsidians/network': `@obsidians/${process.env.BUILD}-network`,
'@obsidians/node': `@obsidians/${process.env.BUILD}-node`,
}),
overrideProcessEnv({
CDN: JSON.stringify(!!process.env.CDN),
BUILD: JSON.stringify(process.env.BUILD),
PROJECT: JSON.stringify(process.env.PROJECT || process.env.BUILD),
PROJECT_NAME: JSON.stringify(process.env.PROJECT_NAME),
OS_IS_LINUX: JSON.stringify(os.type() === 'Linux'),
OS_IS_WINDOWS: JSON.stringify(os.type() === 'Windows_NT'),
OS_IS_MAC: JSON.stringify(os.type() === 'Darwin'),
CHAIN_NAME: '"Xuperchain"',
CHAIN_SHORT_NAME: '"Xuper"',
CHAIN_EXECUTABLE_NAME: '"Xuperchain Node"',
CHAIN_EXECUTABLE_NAME_IN_LABEL: '"Xuperchain node"',
TOKEN_SYMBOL: '""',
COMPILER_NAME: '"Xdev"',
COMPILER_NAME_IN_LABEL: '"Xdev"',
COMPILER_VERSION_KEY: '"xdev"',
DOCKER_IMAGE_NODE: '"obsidians/xuperchain"',
DOCKER_IMAGE_COMPILER: '"xuper/xdev"',
// ENABLE_AUTH: true,
}),
turnOffMangle(),
addWasmLoader(),
]
if (process.env.CDN) {
overrides.unshift(addWebpackExternals({
react: 'React',
'react-dom': 'ReactDOM',
'monaco-editor': 'monaco'
}))
} else {
overrides.push(addWebpackPlugin(
new MonacoWebpackPlugin({
languages: ['json', 'javascript', 'typescript', 'css', 'html', 'markdown', 'c', 'cpp', 'shell']
})
))
}
module.exports = {
webpack: override(...overrides)
}