You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building a framework that have a simple plugins architecture with peerDependencies, where the plugins need to access to some resources of the host project. This scheme is working on Node.js, and I'm trying to mimic it in browsers by following the instructions on the readme to build multiple bundles.
It works as is, but since the framework has some build-in plugins so for basic use cases it can work without any other files, I'm using the standalone option so it can be used from the window object. Problem is, that I've found that by using the standalone option the require() function is not available anymore, so if I want both to access the framework main code from a namespace on the window object and at the same time by doing a require() call (mainly done by the plugins) I need to use an externally provided require() function.
Is it on purpose? Why? What alternatives do I have?
If it's a bug, where should a look to fix it easily?
I'm not sure if it's the same problem, since I've only tested about using standalone & require both over the module itself instead of use standalone over the module and require over one of its dependencies, but I believe both issues are related and it's the same problem.
I've investigated about it and seems the problem is at browser-pack instead, since there's there an if-elseif statement that only allow have enabled one of them...
use the require() generation method giving the package name as the expose argument (this is done automatically on grunt-browseify by settting an alias from the package name to the package main file)
expose the package namespace on the global window object manually:
With this, our package can be used on the browser both with require() and as a global object. I think this is simple enough so it can be added to browser-pack...
Activity
Add note about browserify/browserify#939
nnarhinen commentedon Oct 11, 2014
Is this the same problem I'm facing?
running
browserify index.js -s MySomething -o bundle.jsworks as desired butrunning
browserify index.js -s MySomething -r ./deps/react-proxy.js:react -o bundle.jswhere
./deps-react-proxy.jsisproduces a bundle where
MySomethingis not themodule.exportsfromindex.jsbut it's the same aswindow.React.piranna commentedon Oct 11, 2014
I'm not sure if it's the same problem, since I've only tested about using standalone & require both over the module itself instead of use standalone over the module and require over one of its dependencies, but I believe both issues are related and it's the same problem.
I've investigated about it and seems the problem is at browser-pack instead, since there's there an if-elseif statement that only allow have enabled one of them...
piranna commentedon Oct 17, 2014
We've done a simple workaround:
use the require() generation method giving the package name as the
exposeargument (this is done automatically on grunt-browseify by settting an alias from the package name to the package main file)expose the package namespace on the global
windowobject manually:With this, our package can be used on the browser both with
require()and as a global object. I think this is simple enough so it can be added to browser-pack...jmm commentedon Mar 9, 2015
@nnarhinen I think your issue is what I explain in #1120.
jmm commentedon Mar 9, 2015
I submitted browserify/browser-pack/pull/51 re: this.