fix: inject global object into browser build (closes #77)

This commit is contained in:
Blaine Bublitz 2021-02-10 17:47:48 -07:00
parent 299e72415d
commit 55086be9f1
2 changed files with 8 additions and 0 deletions

@ -1,5 +1,6 @@
import { nodeResolve } from "@rollup/plugin-node-resolve"; import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonJS from "@rollup/plugin-commonjs"; import commonJS from "@rollup/plugin-commonjs";
import inject from "@rollup/plugin-inject";
import virtual from "@rollup/plugin-virtual"; import virtual from "@rollup/plugin-virtual";
import replace from "@rollup/plugin-replace"; import replace from "@rollup/plugin-replace";
import visualizer from "rollup-plugin-visualizer"; import visualizer from "rollup-plugin-visualizer";
@ -23,6 +24,8 @@ export default {
os: empty, os: empty,
crypto: empty, crypto: empty,
readline: empty, readline: empty,
// Stub out a "global" module that we can inject later
global: empty,
}), }),
nodeResolve({ nodeResolve({
browser: true, browser: true,
@ -33,6 +36,10 @@ export default {
replace({ replace({
"process.browser": !!process.env.BROWSER "process.browser": !!process.env.BROWSER
}), }),
inject({
// Inject the "global" virtual module if we see any reference to `global` in the code
global: "global",
}),
visualizer(), visualizer(),
] ]
}; };

@ -48,6 +48,7 @@
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-inject": "^4.0.2",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.1.0", "@rollup/plugin-node-resolve": "^11.1.0",
"@rollup/plugin-replace": "^2.3.4", "@rollup/plugin-replace": "^2.3.4",