-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig-overrides.js
98 lines (85 loc) · 2.07 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
const { addBabelPlugin, override, setWebpackTarget } = require('customize-cra');
// Custom loader for GLSL shaders
const addGlslifyLoader = () => config => {
const loaders = config.module.rules.find(rule => Array.isArray(rule.oneOf)).oneOf;
loaders.unshift({
test: /\.(glsl|frag|vert)$/,
exclude: /node_modules/,
use: [
'raw-loader',
'glslify-loader'
]
});
return config;
};
// Adjust precache maximum to 30 MB
const adjustWorkbox = () => config => {
config.plugins.forEach(p => {
if (p.constructor.name === 'InjectManifest') {
p.config.maximumFileSizeToCacheInBytes = 30 * 1024 * 1024;
}
});
return config;
};
const addDataUriFileLoader = () => config => {
const loaders = config.module.rules.find(rule => Array.isArray(rule.oneOf)).oneOf;
loaders.unshift({
test: /\.datauri$/,
exclude: /node_modules/,
use: [
'raw-loader',
]
});
return config;
};
const addSVGR = () => config => {
const loaders = config.module.rules.find(rule => Array.isArray(rule.oneOf)).oneOf;
loaders.unshift({
test: /\.svg$/,
exclude: /node_modules/,
use: [{
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: [
{
name: 'removeViewBox',
active: false
}
]
}
}
}]
});
return config;
};
patchNpmModules = () => config => {
const loaders = config.module.rules.find(rule => Array.isArray(rule.oneOf)).oneOf;
// NOTE: this is entirely for three's GLTFExporter
// loaders.unshift({
// test: /\.js$/,
// include: /node_modules\/three/,
// use: [{
// loader: 'babel-loader',
// options: {
// plugins: ['@babel/plugin-proposal-optional-chaining']
// }
// }]
// });
return config;
};
module.exports = override(
setWebpackTarget('web'),
adjustWorkbox(),
addBabelPlugin([
'babel-plugin-root-import',
{
'rootPathPrefix': '~',
'rootPathSuffix': 'src'
}
]),
patchNpmModules(),
addGlslifyLoader(),
addDataUriFileLoader(),
addSVGR()
);