-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add support for CommonJS vendors #30
Comments
I think the only reliable solution is to detect two situations described in the README:
|
The require.define({'library/name': function(exports, require, module){ /* Your library */ }}); The problem is that only files with the If I want to use a vendor like mout, I would have add the As I said, I made a solution, that look up the files that are inside a This way I can add the CJS vendors to be found by Sprockets-CommonJS, without having to rename the files. |
@giuliandrimba I understand your problem. I just say that reliable solution would check if script uses |
@sheerun This certainly would be the best approach, I made a test-case locally and it worked perfectly, however, I had some problems. There are scripts that exports only to the Let's take jQuery for instance: jquery-1.10.2.js if ( typeof module === "object" && module && typeof module.exports === "object" ) {
// Expose jQuery as module.exports in loaders that implement the Node
// module pattern (including browserify). Do not create the global, since
// the user will be storing it themselves locally, and globals are frowned
// upon in the Node module world.
module.exports = jQuery;
} else {
// Otherwise expose jQuery to the global object as usual
window.jQuery = window.$ = jQuery;
// Register as a named AMD module, since jQuery can be concatenated with other
// files that may use define, but not via a proper concatenation script that
// understands anonymous AMD modules. A named AMD is safest and most robust
// way to register. Lowercase jquery is used because AMD module names are
// derived from file names, and jQuery is normally delivered in a lowercase
// file name. Do this after creating the global so that if an AMD module wants
// to call noConflict to hide this version of jQuery, it will work.
if ( typeof define === "function" && define.amd ) {
define( "jquery", [], function () { return jQuery; } );
}
} If we search the files content for Eg: require.define({'jquery': function(exports, require, module){
/* jQuery Code */
if ( typeof module === "object" && module && typeof module.exports === "object" ) {
module.exports = jQuery;
} else {
/* IT WON'T EXPORT TO WINDOW, THUS, THE PLUGINS WON'T FIND HIM */
window.jQuery = window.$ = jQuery;
}
}}); A solution for this, is to export jQuery to the What do you think? The code for this change is here (in a different branch) |
One more time: You should check if data.to_s.include?('module.exports') && !data.to_s.match?(/[^\.]define\(/) Of course this Regexp is not enough (for example it fails for some comments and no tabs). |
It isn't possible to load CommonJS vendors that doesn't have the
.module
extension on it, and is not viable to rename all the CommonJS vendor files to include this extension.I made a solution, which check if the file has the
.module
extension on it or the path to the file includes themodules
string (folder).What do you suggest to be the best approach for this?
The text was updated successfully, but these errors were encountered: