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 creating a little extension for React.
I would like to add react as external, and still be able to compile my library as an umd module.
However when using standalone + external I would need that the obtained umd module would be able to fetch 'react' as a global dependencies or as an amd module dependencies, is there a way to do that properly ?
I have submitted a PR to the project that provides the 'standalone' option. If that PR is accepted, then I will submit a PR to node-browserify to support that behavior. ForbesLindesay/umd#19
So bad this issues seems to receive so few support :-(. I would love to see such behaviour.
In the mistime, I found two workaround (none is perfect though).
The first one is using pure-cjs instead of browserify. It handles UMD style export perfectly and if you already know browserify, you almost have nothing to do. It is perfectly compatible with most (all?) browserify transforms.
Unfortunately pure-cis has 2 major disadvantages (in my opinion):
It always reformats your code (actually the results is the output of your source's tree parsed with esprima)
All your dependencies must be accessible by node during the build (event the one you are excluding).
That's the solution I am currently using.
The second one is detailed in this post. The main idea is to generate your umd wrapper yourself (or modifying the template of a UMD generator). It is a little bit harder to do though and looks a little bit hacky...
Once again, @cmaher, I think it is very sad your pull request didn't get accepted.. IMO dependency management is a must have so that you can build good libraries. Because of this missing behaviour, I have seen libs embedding their dependencies in their build, meaning that users must load the library twice if he also needs it..
Activity
mulderp commentedon Mar 16, 2014
I am having a somewhat similar problem, and solve it like this.
In
index.jsI define:Then, I do:
And in
index.html, I add:Would be interesting to hear other's thoughts, if this approach makes sense, or if there are others.
cmaher commentedon Jul 24, 2014
I have submitted a PR to the project that provides the 'standalone' option. If that PR is accepted, then I will submit a PR to node-browserify to support that behavior. ForbesLindesay/umd#19
cmaher commentedon Jul 25, 2014
I am currently handling this with my fork at cmaher/node-browserify like
QuentinRoy commentedon Mar 10, 2015
So bad this issues seems to receive so few support :-(. I would love to see such behaviour.
In the mistime, I found two workaround (none is perfect though).
The first one is using pure-cjs instead of browserify. It handles UMD style export perfectly and if you already know browserify, you almost have nothing to do. It is perfectly compatible with most (all?) browserify transforms.
Unfortunately pure-cis has 2 major disadvantages (in my opinion):
That's the solution I am currently using.
The second one is detailed in this post. The main idea is to generate your umd wrapper yourself (or modifying the template of a UMD generator). It is a little bit harder to do though and looks a little bit hacky...
Once again, @cmaher, I think it is very sad your pull request didn't get accepted.. IMO dependency management is a must have so that you can build good libraries. Because of this missing behaviour, I have seen libs embedding their dependencies in their build, meaning that users must load the library twice if he also needs it..
cmaher commentedon Mar 10, 2015
@QuentinRoy I've actually moved on to webpack, and I've had a great experience with it. https://github.com/cmaher/backbone.hoard/blob/master/gulp/tasks/dist.js generates this wrapper
terinjokes commentedon Apr 24, 2015
@cmaher Bummer your contribution to umd was never accepted. I've seen a couple requests for this feature, and agree it would have been great to add.
Fix distributable to be browserifiable, #12 (browserify/browserify#1151…