-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig-overrides.js
64 lines (61 loc) · 2.2 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
const webpack = require("webpack");
const fs = require("fs");
fs.mkdirSync("public", { recursive: true });
[
{
src: "node_modules/monero-ts/dist/monero.worker.js",
dest: "public/monero.worker.js",
}
].forEach(({ src, dest }) => fs.copyFileSync(src, dest))
module.exports = function override(config) {
const fallback = config.resolve.fallback || {};
Object.assign(fallback, {
crypto: false, // require.resolve("crypto-browserify") can be polyfilled here if needed
stream: require.resolve("stream-browserify"), // require.resolve("stream-browserify") can be polyfilled here if needed
assert: require.resolve("assert"), // require.resolve("assert") can be polyfilled here if needed
http: require.resolve("stream-http"), // require.resolve("stream-http") can be polyfilled here if needed
https: require.resolve("https-browserify"), // require.resolve("https-browserify") can be polyfilled here if needed
os: false, // require.resolve("os-browserify") can be polyfilled here if needed
url: false, // require.resolve("url") can be polyfilled here if needed
zlib: false, // require.resolve("browserify-zlib") can be polyfilled here if needed,
});
config.resolve.fallback = fallback;
config.resolve.alias = {
...config.resolve.alias,
fs: "memfs",
};
config.plugins = (config.plugins || []).concat([
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: ["buffer", "Buffer"],
}),
]);
config.ignoreWarnings = [/Failed to parse source map/];
config.module.rules.push({
test: /\.(js|mjs|jsx)$/,
enforce: "pre",
loader: require.resolve("source-map-loader"),
resolve: {
fullySpecified: false,
},
});
const fileLoaderRule = getFileLoaderRule(config.module.rules);
fileLoaderRule.exclude.push(/\.cjs$/);
config.externals = {
...config.externals,
child_process: 'child_process'
};
return config;
};
function getFileLoaderRule(rules) {
for(const rule of rules) {
if("oneOf" in rule) {
const found = getFileLoaderRule(rule.oneOf);
if(found) {
return found;
}
} else if(rule.test === undefined && rule.type === 'asset/resource') {
return rule;
}
}
}