cjs icon indicating copy to clipboard operation
cjs copied to clipboard

Sourcemaps

Open limikael opened this issue 11 years ago • 3 comments

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.

limikael avatar Jan 17 '14 09:01 limikael

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.

guybedford avatar Jan 19 '14 14:01 guybedford

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?

limikael avatar Jan 20 '14 09:01 limikael

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

guybedford avatar Jan 20 '14 10:01 guybedford