-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcraco.config.js
More file actions
88 lines (83 loc) · 3.02 KB
/
Copy pathcraco.config.js
File metadata and controls
88 lines (83 loc) · 3.02 KB
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
const webpack = require('webpack');
const path = require('path');
module.exports = {
webpack: {
configure: (webpackConfig) => {
// Polyfill fallbacks
webpackConfig.resolve.fallback = {
...webpackConfig.resolve.fallback,
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer'),
crypto: require.resolve('crypto-browserify'),
assert: require.resolve('assert'),
};
// Allow non-fully-specified imports (e.g. 'process/browser')
// required by ESM packages like react-router >=7.12
webpackConfig.module.rules.push({
test: /\.m?js/,
resolve: { fullySpecified: false },
});
// Provide globals
webpackConfig.plugins.push(
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser',
})
);
// Isolate pulse service into its own chunk so ad-blockers
// cannot pattern-match it alongside the main bundle
if (webpackConfig.optimization && webpackConfig.optimization.splitChunks) {
const existingGroups =
webpackConfig.optimization.splitChunks.cacheGroups || {};
webpackConfig.optimization.splitChunks.cacheGroups = {
...existingGroups,
pulse: {
test: /[\\/]services[\\/]pulseService/,
name: 'pulse',
chunks: 'all',
priority: 20,
enforce: true,
},
};
}
return webpackConfig;
},
},
// Dev-server (react-scripts start) overlay filter. troika-three-text (drei's
// <Text>, used for the galaxy axis labels) generates glyph SDFs via WebGL and
// blits them with ANGLE_instanced_arrays. On GPUs/contexts where that
// extension is unavailable it throws "ANGLE_instanced_arrays not supported";
// troika still renders labels via its JS fallback, so the error is benign —
// but webpack-dev-server's runtime-error overlay pops a full-screen red box
// over the app. Suppress that ONE error class in the overlay while keeping it
// for every other runtime error. Dev-only; production has no such overlay.
//
// NOTE: `runtimeErrors` is stringified and shipped to the browser client, so
// this function must be self-contained (no outer-scope references).
devServer: (devServerConfig) => {
const client =
devServerConfig.client && typeof devServerConfig.client === 'object'
? devServerConfig.client
: {};
const overlay =
client.overlay && typeof client.overlay === 'object' ? client.overlay : {};
devServerConfig.client = {
...client,
overlay: {
...overlay,
runtimeErrors: (error) => {
const msg = error && error.message ? error.message : String(error || '');
if (
/ANGLE_instanced_arrays not supported|WebGL (SDF )?generation not supported/.test(
msg
)
) {
return false;
}
return true;
},
},
};
return devServerConfig;
},
};