RequireJS Optimiser "has more than one anonymous define"
Closed this issue · 3 comments
When using RequireJS Optimiser the Optimiser output the following message regarding jquery-hammerjs.
vendor/jquery-hammerjs/jquery.hammer.min.js has more than one anonymous define. May be a built file from another build system like, Ender. Skipping normalization.
should be fixed, see #5
hmm... I'm still seeing two anonymous defines:
https://github.com/EightMedia/jquery.hammer.js/blob/master/jquery.hammer-full.js#L1371
https://github.com/EightMedia/jquery.hammer.js/blob/master/jquery.hammer-full.js#L1490
as a result, here's what's happening:
- user specifies a dependency on jquery-hammer -
require(['jquery', 'path/to/jquery.hammer-full.js'], function($){});
- require fetches
path/to/jquery.hammer-full.js
, file loads and executes - the first
define()
runs, require now thinks the original dependency has been fulfilled so it runs the provided callback - this one:
define(function() {
return Hammer;
});
- the 2nd
define()
runs, require thinks this is a new definition and registers a new module. - now you run
require(['path/to/jquery.hammer-full.js'], function(h){ console.log(h); });
and you get back theHammer
fn - specifically:
function(element, options) {
return new Hammer.Instance(element, options || {});
};
the jquery plugin bits basically never run so you end up with the non-jquery hammer.
a simple fix would be to make the main Hammer module define itself using a specific name - e.g.
define('hammerjs', function() {
return Hammer;
});
...then the definitions don't clash and the 2nd define's 'hammerjs' dependency is immediately fulfilled.. but this isn't ideal.
a better approach would be to massage your build process such that a single module definition (src/outro.js) is included in the built files. i'll try to carve out some time to take a crack at it... but it will likely require PRs to both repos.
anyway, hope this helps some. thanks again for making such a great tool!
-matt
Having the same issue, I think renaming the last "define" in "require" fixes the problem