-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] Replace global objects with polyfills #451
Comments
I think something like this would be good to add. I got most of the way to implementing what is essentially this proposal, but then it occurred to me that there's a more general form of this that would have the same effect here: injecting a small bit of code into each file. You could then specify |
some problems that could arise injecting code in every module are
to overcome these issues you would need to check that the module being injected to does not already define the injected identifiers and you would also need to resolve import paths relative to the importer module |
Yeah I was thinking of doing both of those things. Or more specifically, the injected file would still be a separate file (parsed once and resolved in a specific directory) but esbuild would automatically generate imports of the injected file into each file for all top-level variables not shadowed by that injecting file. |
The final solution is somewhat different than what I proposed above. You have to explicitly export the local variables you want to expose as globals. There is more information in the release notes. |
My use case is to replace the
process
global object with a polyfillYou could do that adding an option to replace global objects with modules, this way you can for example replace the
process
global object with a polyfill stored in a local file that has the process polyfill as default exportExample
Building with a setting like
--inject=proces:process-polyfill.js
The code below
Would become
This feature request is similar to what the
@rollup/plugin-inject
does in rollupThe text was updated successfully, but these errors were encountered: