-
Notifications
You must be signed in to change notification settings - Fork 20
/
config-overrides.js
144 lines (134 loc) · 4.62 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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 (rules && 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
}
}
];
config.resolve.fallback = fallback;
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: 'oraidex',
authToken: process.env.SENTRY_AUTH_TOKEN
})
);
}
config.plugins.push(
new webpack.DllReferencePlugin({
context: __dirname,
manifest
})
);
return config;
},
devServer: function (configFunction) {
// Return the replacement function for create-react-app to use to generate the Webpack
// Development Server config. "configFunction" is the function that would normally have
// been used to generate the Webpack Development server config - you can use it to create
// a starting configuration to then modify instead of having to create a config from scratch.
return function (proxy, allowedHost) {
// Create the default config by calling configFunction with the proxy/allowedHost parameters
const config = configFunction(proxy, allowedHost);
// Change the https certificate options to match your certificate, using the .env file to
// set the file paths & passphrase.
config.proxy = [
{
context: ['/v3'],
// target: 'http://localhost:3001',
changeOrigin: true
}
];
// Return your customised Webpack Development Server config.
return config;
};
},
jest: (config) => {
config.setupFiles = ['<rootDir>/jest.setup.ts'];
return config;
}
};