-
Notifications
You must be signed in to change notification settings - Fork 1
/
config-overrides.js
121 lines (113 loc) · 3.61 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
113
114
115
116
117
118
119
120
121
const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const { execFileSync } = require('child_process');
const paths = require('react-scripts/config/paths');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const fallback = {
fs: false,
tls: false,
net: false,
os: false,
url: false,
path: false,
assert: false,
querystring: false,
http: require.resolve('stream-http'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer'),
https: require.resolve('https-browserify')
};
const fixBabelRules = (config) => {
// find first loader and use babel.config.js
let ruleInd = 0;
let firstRule = true;
const rules = config.module.rules[0].oneOf;
while (ruleInd < rules.length) {
const rule = rules[ruleInd];
if (rule.loader) {
if (firstRule) {
// ignore js and mjs and use just one
rule.test = /\.(jsx|ts|tsx)$/;
rule.options.plugins.push([
'@oraichain/operator-overloading',
{
classNames: ['BigDecimal']
}
]);
firstRule = false;
} else {
rules.splice(ruleInd, 1);
continue;
}
}
ruleInd++;
}
};
module.exports = {
fallback,
webpack: function (config, env) {
fixBabelRules(config);
config.module.rules = [
...config.module.rules,
{
test: /\.m?js/,
resolve: {
fullySpecified: false
}
}
];
const isDevelopment = env === 'development';
// do not check issues
config.plugins = config.plugins.filter((plugin) => plugin.constructor.name !== 'ForkTsCheckerWebpackPlugin');
config.resolve.plugins = config.resolve.plugins.filter((plugin) => !(plugin instanceof ModuleScopePlugin));
config.plugins = [...config.plugins, new NodePolyfillPlugin()];
// update vendor hash
const vendorPath = path.resolve('node_modules', '.cache', 'vendor');
const vendorHash = webpack.util.createHash('sha256').update(fs.readFileSync('yarn.lock')).digest('hex').slice(-8);
const interpolateHtmlPlugin = config.plugins.find((c) => c.constructor.name === 'InterpolateHtmlPlugin');
interpolateHtmlPlugin.replacements.VENDOR_VERSION = vendorHash;
// add dll
const manifest = path.join(vendorPath, `manifest.${vendorHash}.json`);
if (fs.existsSync(manifest)) {
console.log(`Already build vendor.${vendorHash}.js`);
} else {
execFileSync('node', ['scripts/vendor.js', vendorPath, vendorHash], {
stdio: 'inherit',
env: process.env,
cwd: process.cwd()
});
}
// try copy from cache to public for later copy
const vendorFileSrc = path.join(vendorPath, `vendor.${vendorHash}.js`);
const vendorFileDest = path.join(paths.appPublic, `vendor.${vendorHash}.js`);
if (!fs.existsSync(vendorFileDest)) {
fs.copyFileSync(vendorFileSrc, vendorFileDest);
}
if (!isDevelopment && process.env.SENTRY_AUTH_TOKEN) {
config.devtool = 'source-map';
config.plugins.push(
sentryWebpackPlugin({
org: 'oraichain',
project: 'homebase',
authToken: process.env.SENTRY_AUTH_TOKEN
})
);
}
config.plugins.push(
new webpack.DllReferencePlugin({
context: __dirname,
manifest,
scope: 'src'
})
);
return config;
},
jest: (config) => {
config.setupFiles = ['<rootDir>/jest.setup.ts'];
return config;
}
};