-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
use an interopDefault function for external CJS deps #458
Conversation
Good idea. To ensure that we don't get any name collisions, we should probably add |
$ = 'default' in $ ? $['default'] : $; | ||
function _interopRequire (id) { var ex = require(id); return 'default' in ex ? ex['default'] : ex; } | ||
|
||
var $ = _interopRequire('jquery'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be done in two steps like it was before, otherwise using browserify
or the like on the output won't really work. Unless I'm missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is, there should still be a require('jquery')
for such tools to find.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e.
function _interopRequire (mod) { return 'default' in mod ? mod['default'] : mod; }
var $ = _interopRequire(require('jquery'));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you're right -- it'll have to be a two-step process.
I agree with @eventualbuddha. @aearly Also just noticed that the var alphabet = require('alphabet');
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet; This PR // alphabet equals alphabet__default, although it shouldn't
var alphabet = _interopRequire('alphabet');
var alphabet__default = alphabet; What we want is to extract the var alphabet = require('alphabet');
var alphabet__default = _interopRequire(alphabet); |
… cjs work with browserify
One other thing -- we can also do something similar for the AMD/UMD/IIFE outputs too by modifying |
use an interopDefault function for external CJS deps
awesome, thanks @aearly! |
Closes #419 . Also makes async's modular builds a bit smaller. :)