-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-overrides.js
110 lines (108 loc) · 3.53 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
// INFO about this file in https://github.com/timarney/react-app-rewired
/* eslint @typescript-eslint/no-var-requires: "off" */
const {
override,
addWebpackResolve,
addWebpackPlugin,
overrideDevServer
} = require("customize-cra");
const webpack = require("webpack");
const devServerConfig = () => (config) => {
return {
...config,
open: ["/#/dev"]
};
};
module.exports = {
// The Webpack config to use when compiling your react app for development or production.
webpack: override(
(config) => {
config.ignoreWarnings = [
/Failed to parse source map/,
/Critical dependency: Accessing import\.meta directly is unsupported \(only property access or destructuring is supported\)/
];
return config;
},
addWebpackResolve({
fallback: {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
path: require.resolve("path-browserify"),
constants: require.resolve("constants-browserify"),
fs: require.resolve("browserify-fs"),
assert: require.resolve("assert"),
buffer: require.resolve("buffer")
}
}),
// Work around for Buffer is undefined:
// https://github.com/webpack/changelog-v5/issues/10
addWebpackPlugin(
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"]
})
// ),
// addWebpackPlugin(
// new webpack.ProvidePlugin({
// process: "process/browser"
// })
),
(config) => {
if (config.module) {
config.module.rules = config.module.rules?.map((rule) => {
if (!("test" in rule) && "oneOf" in rule) {
const r = {
...rule,
oneOf: rule.oneOf.map((innerRule) => {
return "test" in innerRule &&
((typeof innerRule.test === "function" &&
innerRule.test(".svg")) ||
(innerRule.test[0] &&
typeof innerRule.test[0].test === "function" &&
innerRule.test[0].test(".svg")))
? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
{ ...innerRule, exclude: /assets.+\.svg$/ }
: innerRule;
})
};
r.oneOf.unshift({
test: /\.svg$/,
// use: ["@svgr/webpack"]
use: [
{
loader: "@svgr/webpack",
options: {
svgoConfig: {
plugins: [
{
name: "preset-default",
params: {
overrides: {
// disable plugins
removeViewBox: false
}
}
}
]
}
}
}
]
});
return r;
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return "test" in rule && rule.test.test(".svg")
? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
{ ...rule, exclude: /assets.+\.svg$/ }
: rule;
});
}
config.plugins = config.plugins?.filter((plugin) => !!plugin);
return config;
}
),
devServer: overrideDevServer(devServerConfig())
};