-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
AMD with concatenated JS file #13812
Comments
Also, RequireJS doesn't seem to like how we declare these modules, using either of the two methods, it doesn't wait for the file to load and execute. This is rather complex from what I can tell while working on some AMD examples/tests... I say we revert UMD in master for now, put it in a separate branch and punt it to 3.3. I image that 3.2 must be long overdue now and shipping UMD with a major problem like this doesn't seem like a good idea. Also, Bootstrap can be easily used with RequireJS right now without the definitions, it just needs some shimming. |
If fixed this, although in a rather hacky way, see hnrch02@060f3fc. |
Will hopefully revert this reversion and land a fully-working version of UMD in v3.3.0. Revert "some changes from #13801 - add strict mode back and ==" This reverts commit 2b302f6. Revert "Fix regression of #10038 introduced by #13772" This reverts commit e9d6756. Revert "MD/CommonJS/Globals #12909" This reverts commit 1c6fa90. Revert "address #13811" This reverts commit f347d7d. Conflicts: js/carousel.js js/collapse.js js/dropdown.js js/modal.js js/tab.js js/tooltip.js
why? |
Which branch or tag is using AMD? |
None. |
😥 But you should create a new tag (v3.1.2) and not replace the current release! I think! |
3.1.1 did not include anything UMD related, you were using bleeding edge code and that comes with the danger of us removing stuff we previously added. |
Exactly what @hnrch02 says. It will be implemented properly in the next release. |
oh yeah!! I cloned from the master branch... sorry... 🍻 |
by the way... |
My tests concluded something else, please give more insight into your setup. |
This is the small project: https://github.com/lagden/textela I use VoloJS to set libraries and There's nothing special!! Here is my config file: I used Setting the library on Defining on module To dev: Grunt server running on To optimize:
Run: My Some requirements are:
It might help!! |
I don't think you understand the problem this issue is describing. You are requiring some of our plugins individually, not using all of them via the concatenated file. |
I understand... tooltip load jquery I'll do it this way: // tooltip.js
(function(factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else {
// Browser globals
factory(jQuery);
}
}(function($) {
//... some code
$.fn[pluginName] = function(options) {
return this;
};
}));
// popover.js
(function(factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['tooltip'], factory);
} else {
// Browser globals
factory(jQuery);
}
}(function($) {
//... some code
$.fn[pluginName] = function(options) {
return this;
};
}));
// concat and compressed
(function(e){if(typeof define==="function"&&define.amd){define(["jquery"],e)}else{e(jQuery)}})(function(e){e.fn[pluginName]=function(e){return this}});(function(e){if(typeof define==="function"&&define.amd){define(["tooltip"],e)}else{e(jQuery)}})(function(e){e.fn[pluginName]=function(e){return this}}) |
That's where this problem comes in. Per the AMD spec there must only ever be one |
Apparently Bundles might be a (partial) solution?: |
Though that would still require configuration on the side of the end-user. |
Yeap... I never seen other way... About bundles: |
Reading all the resources, Bundles seem to fix the problem but don't really solve it. RequireJS would accept our file, the user would still need to require each and every one of our plugins manually. |
@hnrch02 - #13843 This makes the assumption that you are going to just plug and play the entire library. Most likely however, users consuming the library via module system, common or amd, are looking to incorporate individual modules. UMD should be incorporated on the final concatenated file, however this is only half of the problem. Pointing back to (Lodash): Core - implements a UMD wrapper (this is the file found on cdn's etc...) |
@jaridmargolin Not sure I'm following, this would have been totally possible in a CommonJS environment: var $ = require('jquery')
require('bootstrap/js/modal')
$('#myModal').modal() and in AMD: define(['jquery', 'bootstrap.modal'], function($) {
$('#myModal').modal()
}) The only thing that was missing from these individual UMD definitions was the dependency of certain plugins on |
Apologies for my last comment. I looked at master, which currently does not contain the following snippet in each module:
and I looked at the changed files referenced in #13843. Between the two it appeared to me that you were just throwing a giant UMD wrapper around the concatenated file and calling that good enough. Should have reviewed a little more thoroughly before commenting. Back to Lodash (last time I promise). By creating three different distributions, you remove the complexity of trying to have one solution that works in multiple environments. No if/else logic or unnecessary boiler in each file. Just a single build process. |
I see how that's appropriate for something like Lo-Dash with their very fancy build system and complex structure but I think for our purpose the boilerplate in each file that gets stripped if plugins are concatenated will do the job. But that's just me, we need @fat's @cvrebert's and @XhmikosR's opinion on this. |
hauhauhau... awesome!!! |
Punting to the v4 checklist. |
The problem is that you can only have one
define
call within the same file, unless you specify a name that substitutes the file name which would normal determine the name of the module. This is currently not the case with our UMD code and makes the concatenated JS file not work with AMD.I did some more tinkering with this and came to the conclusion that we have two options:
This would solve the problem, but create a new one: You'd need to
require
all plugins individually like so:Then you'd require Bootstrap like this and you'd be good to go:
I prefer option 2, but I don't know if that has downsides. I can't think of any, as we're not exporting anything that could be used in the
require
call by the end user./cc @fat @cvrebert @XhmikosR
The text was updated successfully, but these errors were encountered: