requirejs / r.js

Runs RequireJS in Node and Rhino, and used to run the RequireJS optimizer
Other
2.57k stars 672 forks source link

r.js optimizer should adjust package dependencies to match generated module names #136

Closed jeffbski closed 12 years ago

jeffbski commented 12 years ago

I am just having one issue when it comes to using packages, relative names, and the resulting optimized code.

In a nutshell, say I have code in a package structure, r.js does a good job generating the module names like'store', 'store/util'.

However it does not adjust the original relative dependency which still is listed as './util'.

So because of this, the optimized single file code won't load in almond (it is looking for ./util but can't find it since it is named store/util. Also even to use the optimized file in requirejs, I would still need to do a require.config, to let it know that store is a package, otherwise it won't find the file either.

To test my theory, I have manually changed the './util' to 'store/util' in the generated dist.js and both of these issues go away.

r.js should adjust the dependency name from './util' to 'store/util' so that it matches the define module name 'store/util'.

Then everything will work great in almond, and you won't even need to do all the config stuff to use in requirejs or another amd.

This would allow us to be able to distribute with almond and/or requirejs (without needing all the config setup).

See the full gist here: https://gist.github.com/2243210

Also the corresponding discussion on the requirejs google group: https://groups.google.com/forum/?fromgroups#!topic/requirejs/j3u4T6Chvqw

If this feature/change were accepted, then everything is beautiful, I can deliver my code for anyone to use with or without requirejs. Almond option for browser, amdefine option for node.js, and requirejs if they need full featured loading in either.

Please note: James' response to my question also mentioned that store, should create store/main adapter, but honestly I'm not sure if that is needed, since I think I only ran into the issue for the relative files. I could be missing something, but I think just changing the relative dependencies to match will cover the issues I ran into.

Basically the goal is that r.js optimized code containing packages, should have their relative dependency files named the same as the generated module names, so that simple loaders can simply match them up without knowing anything else about the original structure of the files (no config needed), should load straight into almond or any AMD just by giving the optimized dist file.

I will attempt to create a test for this as soon as I can. (I just have to figure out how to do that in your test suite :-) I can also take a look to see if I can find where to make the change, but may take me a while since am not familiar with the code base yet.

Thanks for an awesome project, this has made things so much better in letting us use code optimally in both browser and server environment. It just works!

Jeff

jrburke commented 12 years ago

This will be in the 2.0.1 release, it writes out a shim module for the just 'packageName', this allows it to work in require.js and almond after a build. You can try it right now using this master snapshot:

https://raw.github.com/jrburke/r.js/master/dist/r.js

jeffbski commented 12 years ago

Thanks Jim, I will check it out!

On Fri, Jun 1, 2012 at 2:06 PM, James Burke < reply@reply.github.com

wrote:

This will be in the 2.0.1 release, it writes out a shim module for the just 'packageName', this allows it to work in require.js and almond after a build. You can try it right now using this master snapshot:

https://raw.github.com/jrburke/r.js/master/dist/r.js


Reply to this email directly or view it on GitHub: https://github.com/jrburke/r.js/issues/136#issuecomment-6068350

Jeff Barczewski Inspired Horizons http://inspiredhorizons.com/ Professional Software Craftsmanship