requirejs / almond

A minimal AMD API implementation for use after optimized builds
Other
2.42k stars 169 forks source link

define() without name #80

Closed kof closed 10 years ago

kof commented 10 years ago

Requirejs does support this, almond - not. Is there any reason for this?

define(function() {}) will trigger an error.

kof commented 10 years ago

oh its because of the amd standard...

kof commented 10 years ago

Actually the problem is most libraries do check if define.amd and use define(function() {}) then ... so either almond should support this pattern or remove define.amd object to let it work.

jrburke commented 10 years ago

almond is for built files. Multiple anonymous define() calls in built files that contain multiple modules cannot work in any loader, even in requirejs, which is why this is not supported in almond --- it is not possible to know what module ID gets the define() definition in that case.

For single file scripts loaded dynamically by requirejs, the loader can know the name since it loaded the script, but even in that case, the file loaded can only have one anonymous define() call in it. If it has more than one (which is the case for build situations where almond is used) it would break too.

The fix in this case is to use an AMD-aware optimization tool that inserts the names for the anonymous modules. A plain concatenation of AMD modules will not work, for any AMD loader.