forked from tokenocean/raretoshi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamShim.js
42 lines (39 loc) · 1.16 KB
/
streamShim.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
export default () => ({
name: "shim",
config: (config) => {
if (!config) config = {};
if (!config.resolve) config.resolve = {};
if (!config.resolve.alias) config.resolve.alias = {};
// Node style imports are used throughout the library,
// these are browser compatible versions. Webpack 4 used
// to shim these automatically, but increasingly modern
// build tools don't, as we shouldn't be dropping server
// shims into browsers.
//
// I agree, and we should be working to actually fix React PDF
// but this shim keeps us working as we do.
if (Array.isArray(config.resolve.alias)) {
config.resolve.alias.push(
{
find: "process",
replacement: "process/browser",
},
{
find: "stream",
replacement: "vite-compatible-readable-stream",
},
{
find: "zlib",
replacement: "browserify-zlib",
}
);
} else {
config.resolve.alias = {
...config.resolve.alias,
process: "process/browser",
stream: "vite-compatible-readable-stream",
zlib: "browserify-zlib",
};
}
},
});