Skip to content

Source map support - #50

Merged
guybedford merged 4 commits into
requirejs:masterfrom
lavrton:master
Jun 23, 2013
Merged

guybedford merged 4 commits into
requirejs:masterfrom
lavrton:master

Conversation

@lavrton

@lavrton lavrton commented May 31, 2013

Copy link
Copy Markdown
Contributor

I have to add other base64 implementation, because i had problems with "btoa" function and unicode.

@jrburke

jrburke commented Jun 3, 2013

Copy link
Copy Markdown
Member

I will leave it to @guybedford to comment more, but my first thought is that source map support should avoid using inline data: URLs for the full source map -- it makes the files very large, and hurts download speeds. I prefer to just have a pointer to the sourcemap file, as then that data is not downloaded to the browser unless debugging is actually desired.

@lavrton

lavrton commented Jun 4, 2013

Copy link
Copy Markdown
Contributor Author

To avoid using inline data you have to generate source map, save them somewhere - too many steps to make it works. With inline data everything work out of the box.

it makes the files very large, and hurts download speeds

I think this is very bad way to deploy "develop code" to production. Better way is to use r.js, then deploy results minified and with no source maps.

@jrburke

jrburke commented Jun 4, 2013

Copy link
Copy Markdown
Member

Now that r.js supports generating source maps from minified, bundled code all the way back to non-minified, separate JS files, it seems useful to figure out how to do from separate JS files back to coffeescript files.

In other words, the steps to save the map files are already there for separate files, and it gives people a way to debug their minified code. That seems to be a larger win than something that would only make sense before minifying, but I leave it to @guybedford.

@ssafejava

Copy link
Copy Markdown

In development, this patch makes a lot of sense - require-cs doesn't have filesystem access so it has no choice but to put the source map directly into the code to be evaled, and afaik the only way to do that given the current sourceMappingURL scheme is via a data-uri. So this patch is the right solution for development given the constraints of being in the browser.

I think that using require-cs in production (at all) is the wrong move and will continue to cause problems because of its lack of filesystem access.

Deployments made to production really ought to be using r.js, in which case it makes the most sense to exclude using require-cs entirely. cs.js could be stubbed to become a simple source passthrough, and the developer would compile using e.g. grunt-contrib-coffee or coffeeify, which can generate source maps as separate files.

The real kicker is patching r.js to accept pre-existing source maps, much like uglify2 accepts source maps. Then we could pass 3 levels of source maps through(!) all the way to production:

CoffeeScript -> JS -> Bundled Modules (r.js) -> Minified Production Module (uglifyJS)

@lavrton lavrton mentioned this pull request Jun 21, 2013
@ichernev

Copy link
Copy Markdown

If I'm not mistaken, there are 2 missing pieces at the moment:

  1. plugins (require-cs) can't pass source maps to main r.js, because of the way requirejs plugins work
  2. once we have the maps, to use them as input of the concatenation process (somewhere here https://github.com/jrburke/r.js/blob/master/build/jslib/build.js#L1671). This is already implemented in here (https://github.com/g-k/source-map-cat) -- tried it and it works. Also the code looks pretty straight forward.

@guybedford
guybedford merged commit 8f93211 into requirejs:master Jun 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants