Prevent that "require" is exposed as global function
See original GitHub issueWhy does parcel build
create build files that expose a global require
function and is there a way to prevent that?
// beginning of js build file
require=function(r,e,n) {...
🤔 Expected Behavior
When parcel is used to build libraries that are loaded on 3rd party websites, it should prevent to expose a global require
function, because other scripts on that site could rely on a global require
function.
😯 Current Behavior
When loading a JS file, which was built with parcel, it exposes require on the window object.
💁 Possible Solution
Add the possibility to configure, if require gets exposed or not.
🔦 Context
Loaded a JS build on a foreign website which relied on a different global require.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How do you expose a global javascript function without ESLint ...
According to eslint.org adding /* export Counter */ should have worked, unless it's specifically for variables and not standalone functions.
Read more >Avoid usage of global functions · Issue #3645 · twigphp/Twig
I'm currently using the box project and its php scoper but twig can currently not scoped away because of this global function requirements....
Read more >globalThis - JavaScript - MDN Web Docs
Note: The globalThis property is configurable and writable so that code authors can hide it when executing untrusted code and prevent exposing ......
Read more >why are globals bad in javascript [duplicate]
The global scope is not yours to mess with. The only legitimate reason for using the global scope is in order to expose...
Read more >TypeScript: exposing module types in the global context and ...
So the initial idea was to take a few functions, wrap them in a module, load the module back into the global scope...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@devinrhode2 the solution was that the function name
require
is not used anymore (which is utilized by RequireJS and some other loaders) and instead usesparcelRequire
as global.What was the solution? Does parcel still create it’s own require function?