scalableminds / amd-optimize

An AMD (RequireJS) optimizer that's stream-friendly. Made for gulp.
MIT License
162 stars 29 forks source link

CommonJS syntax does not work when not storing into variable #17

Closed smajl closed 10 years ago

smajl commented 10 years ago

When I have this on the root file:

define(function(require) {
  require('path/to/dep');
});

Then dependency chaining does not work. If I rewrite it in array syntax it does kick in... Bug?

smajl commented 10 years ago

I have specified the problem... Shortened syntax not working just on the first file. Strange..

normanrz commented 10 years ago

Thanks for posting this issue. It is weird, because it is the test case I just added in https://github.com/scalableminds/amd-optimize/commit/8033ffcc003c2e26037787fef5ed335fded7993f. And that worked out of the box.

Does the plugin not emit the dependency files? Can you tell me what the output of the plugin is?

smajl commented 10 years ago

Great, I found out where the problem is and I hope you can easily fix that now. :)

The problem is, tadaaaa, if you don't store the module export in a variable, amdOptimize will not load it... ;)

require('dep'); // does not work
var dep = require('dep'); // works

I have a lot of first case requires in my app, cause these modules often just register angular modules (no need to export something directly). :)

normanrz commented 10 years ago

Thanks for debugging. This was indeed easy to fix. I just released a patch, can you confirm that it works?

smajl commented 10 years ago

0.2.4 fixed that, marvelous. Thanks for your cooperation. :)