-
-
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
Provide scope for require() or require.noConflict() #403
Comments
browserify falls back (and doesn't overwrite) any pre-existing 'require' that is in scope. Also, browserify doesn't add anything to the global scope unless it is explicitly told to. (as far as I can tell) are you sure this is actually a problem? are you using the latest browserify? |
I agree that it's not a problem in most cases. I'm mainly worried about trying to use https://github.com/substack/node-browserify#multiple-bundles when there is an incompatible require function defined on the page. By "incompatible", I mean the page defines a I can probably work around this by ensuring all browserified files execute together and in the right order, but it would be nice if I could specify a context or an alternate name for |
Also, as of browserify v2.12.5, it appears to overwrite an existing |
the best way would be to wrap encapsulate that thing in a closure, (or the browserify bundles) ';(function (require) {' + bundle + '})(' + noConflict + ');' it's getting complicated to add this as a feature to browserify, you should make another module to do this and publish on npm! |
I think the best way to handle this right now is to just wrap the bundle output. |
I'm using browserify to compile code for widgets and libraries that can be included on other people's pages. Ideally, it would be nice to avoid conflicts with pages that use some kind of CommonJS or AMD loading using either a standard
noConflict([parent object])
method or an option provided to browserify. I can't trust publishers using this code to have a compatible implementation ofrequire
, so browserify's version needs to be sandboxed from theirs.Basically, I want the
require
method to be attached to a global object of my choice, and for all bundles to use this reference somehow instead ofwindow.require
- an example of this can be found in the easyXDM library.@substack I know you've worked some related ideas with substack/yarnify - any suggestions on how this could work? I think browserify could be incredibly useful for bundling third-party JS libraries if this is possible.
The text was updated successfully, but these errors were encountered: