mariusGundersen / gulp-amd-optimizer

Emits the entire dependency tree of one or more AMD modules, from leaves to root, and names anonymous modules
22 stars 4 forks source link

It's looking in the wrong directory #7

Open thany opened 8 years ago

thany commented 8 years ago

It seems as if it always tries to load a module from the baseUrl:

Could not load `./app`
required by `js/main`
from path `source\app.js`

But app.js is in source\js\app.js, next to main.js. That's what ./app.js means.

Before amd-optimizer it works fine, when I let require.js do it's thing just in the browser.

mariusGundersen commented 8 years ago

What does your gulp.src() look like? You should probably try to use the option object to set the base. Have a look at the example in the readme

thany commented 8 years ago

Doesn't really matter, now does it? the . mean to look in the directory where the caller is located. That doesn't really have anything to do with any base url.

But if you think it'll help, my src is set as ['source/js/**/*.js']. I've also tried just ['source/js/main.js'] which makes it unable to find a whole bunch of other includes. Really strange, since main.js is the entry point, so I don't know why that makes any difference for how it searches for the includes.

Further, setting base to source or source/js also makes it unable to find includes, differing ones again.

But no matter how you put it, . should mean "current directory", regardless of anything.

thany commented 8 years ago

Update: I got it working. But with so many places where a dir, subdir, option or something else could be missing or must be provided, I have no clue why I got it working. I don't think I changed anything.

I hope this won't be another Grunt problem (which I thouroughly hate) where it 'suddenly' works and I add a comment promising to punish anyone who touches anything :)

mariusGundersen commented 8 years ago

ah, sorry, unfortunately relative module loading doesn't work very well, so you can't really do require('./app', ...). This tool is designed for frontend website stuff, and so it might not map very well to what you are used to from for example CJS, unfortunately :-/

I suggest you use absolute urls from some base place all the time, and that you include .js in the path you require. I haven't tested how it works without these, so I can't guarantee that it will work. If you want to help me make it work I would love your thoughts on it!

mariusGundersen commented 8 years ago

Eh, sorry, now I'm confusing myself! You shouldn't have the .js, obviously. But, relative modules are still not recommended with AMD.