Jerome WAGNER
Jerome WAGNER

Reputation: 22442

how can I enable a source map for coffeescript?

I recently discovered the existence of source maps in chrome via source debugging in the haxe language. It allows to debug generated javascript inside the chrome browser while seeing the bug reason in the original source code.

Has anyone written a source map generator for coffeescript / Is coffeescript source mappable ?

It would help debug the javascript generated by coffeescript.

Upvotes: 21

Views: 10241

Answers (4)

Lucia
Lucia

Reputation: 13597

Ps, if you're on vim, use:

au BufWritePost *.coffee silent make -m

which compiles with source map on file save. I've found it extremely handy when I want some random buffer to start compiling coffee for me.

Upvotes: 0

mquandalle
mquandalle

Reputation: 2598

Coffeescript 1.6 has native support for source maps.

Use the "--map" or "-m" option to enable it. Or if you use the npm compiler, you will have to add the sourceMap: true option.

Upvotes: 26

Ajay M
Ajay M

Reputation: 71

npm install -g coffee-script

Should install coffee-script as a global module. Check version > 1.6 by typing

coffee -v

If you need help you can use. Use it to see meaning of options used below

coffee -h

For regular compilation use

coffee -mo script/ -cw src/

This should auto-generate maps files. I leave this running in terminal as I code, it compiles every time I save.

KNOWN BUG:

The current coffee-script compiler does not seem to handle different /src and /script directories. In map file you find that sources = {filename} rather than {relative file path}.

SOLUTION:

  1. Keep your .coffee files in same directory as .js
  2. Modify source directive manually in .map file. This will get overwritten again on next save

Upvotes: 7

Trevor Burnham
Trevor Burnham

Reputation: 77426

This has long been an active issue on the CoffeeScript project (indeed, it predates the source map standard). However, no (complete) CoffeeScript source map generator exists yet. For discussion, see https://github.com/jashkenas/coffee-script/issues/558

Source map support is also one of the goals of the "CoffeeScript Redux" compiler that was recently funded on Kickstarter (see http://www.kickstarter.com/projects/michaelficarra/make-a-better-coffeescript-compiler). That project has just begun; you can watch it at https://github.com/michaelficarra/CoffeeScriptRedux

Upvotes: 5

Related Questions