guybedford / cjs

CommonJS loader plugin for RequireJS
MIT License
17 stars 4 forks source link

Sourcemaps #2

Open limikael opened 10 years ago

limikael commented 10 years ago

I'm using cjs and with it I can write my files using the cleaner CommonJS syntax, but use them in a RequireJS environment. No other method that I have tried allows me to do that. So great work! Thanks!

My question is, is there any way to get sourcemaps to work with cjs? Don't know if this is something that would need to go into amd-loader or cjs or both.

guybedford commented 10 years ago

Do you mean something like changing line 13 to:

callback('define(function(require, exports, module) { (function(){var define=undefined;' + source + ' \n//# sourceURL=' + req.toUrl(name) + '\n})() });');

A sourceURL comment like that should give useful debugging.

limikael commented 10 years ago

That worked beautifully! Thanks! Will you patch the "mainline" with this also?

On a separate note, I read what you wrote as a comment to another issue:

I'm still not sure if I really want to support this module, hence the lack of this at the moment. The thing is once code is loaded through XHR one might as well use an XHR-based loader instead of RequireJS.

And I just want to mention that I really think it is worth supporting. As I wrote, I have not found any other solution in my particular scenario where I can use a CommonJS syntax and combine it with existing AMD modules. The reason here why I want to use the CommonJS syntax is that it is cleaner, it is newly developed code so it would be possible to write it in AMD syntax, but I prefer the CommonJS syntax because it is cleaner and less error prone.

Maybe I haven't been looking enough though for another solution, which are those XHR based loaders that could potentially do that?

guybedford commented 10 years ago

Glad to hear it worked and you like the ideas!

This one is the loader I'm focusing on at the moment - http://github.com/guybedford/systemjs