-
Notifications
You must be signed in to change notification settings - Fork 28
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
umd-packaged modules don't work with packaging systems that detect the require
calls and assume they are global
#10
Comments
+1, UMD isn't Universal Module Definition without that. |
Agreed, we should probably do this via uglify-js since we already depend on that. |
I don't really understand the muffinization here. Wouldn't it be browserify's job to make sure that I think what we are missing is something in umd to support generating code such like https://github.com/umdjs/umd/blob/master/returnExports.js#L25 with an easy interface for browserify to tap into. |
This is probably something that detective should handle, similarly to how in insert-module-globals there are checks to make sure the expected names aren't from local definitions using lexical-scope. |
browserify isn't the only packaging system that gets bitten by this though. It would be nice if any consumer of this module could have this fixed for them. I'm with @andreypopp that UMD isn't universal unless |
I think it's worth fixing but it will be a while before I get any time to do it myself. |
I actually wrote a very rough grunt task to do this, don't use it in production, it's terrible, but it works and could serve as a starting off point. edit, extracted the relevant code into it's own repo |
@calvinmetcalf thanks for that 👍 @substack makes sense! @petehunt maybe umd calls out to detective? |
require
calls and assume they are global
See #11. I think this is best left as out of scope for this module. |
UMD-packaged modules are designed to work in any environment. Unfortunately they don't work in very many client-side packaging systems (I tried
browserify
andrequirejs
,webpack
works).Here's the scenario:
./x.js
requires./y.js
and we dobrowserify --standalone x x.js > ./temp/a.js
. If I requirea
from Node or drop it in a browser everything works. Great.Now I create
./temp/b.js
which requires./a.js
and I dobrowserify b.js
from./temp/
. It throws withError: Cannot find module './y'
because the wordrequire()
is used within the source still.This is common behavior in many of the popular browser packaging systems I mentioned. They just look for calls to a function named
require()
.My solution to this is to syntax transform the
require
literal when used as a function argument or function call tomuffin
. Would a pull request that does something like this (with a more mangled identifier) be accepted? It would require esprima.The text was updated successfully, but these errors were encountered: