AMD with concatenated JS file
Created by: hnrch02
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:
- We process the source files in the concatenation step to replace part of the UMD code to look like this:
typeof define == 'function' && define.amd ? define('bs.<PLUGIN_NAME>', ['jquery'], o_o)
This would solve the problem, but create a new one: You'd need to require
all plugins individually like so:
require(['jquery', 'bs.affix', 'bs.alert', ...], function ($) {
!!$.fn.affix // -> true
})
- We process the source files in the concatenation step to replace part of the UMD code to look like this:
typeof define == 'function' && define.amd && typeof require == 'function' ? require(['jquery'], o_o)
Then you'd require Bootstrap like this and you'd be good to go:
require(['jquery', 'bootstrap'], function ($) {
!!$.fn.affix // -> true
})
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