-
Notifications
You must be signed in to change notification settings - Fork 10
Source maps with closure compiler
refractalize edited this page May 24, 2012
·
1 revision
An experiment in using Source Maps, mapping compiled javascript back into the original source file (coffee, pogo, unminified js, etc.)
brew install closure-compiler
- Write some js into
afile.js
closure --create_source_map 'afile.js.map' --source_map_format V3 afile.js > afile.min.js
- Add the line
//@ sourceMappingURL=afile.js.map
to the bottom ofafile.min.js
. I have no idea why the closure compiler doens't do this for you. - Write a HTML page that loads
afile.js.map
- Point your browser (Firefox or Chrome) at the html page.
- Go to the browser debugger, open the settings and enable source maps.
- Check out the error in the console, it should be pointing to a source location in
afile.js
.
There's a node.js module for reading and writing source maps here: https://github.com/mozilla/source-maps
According to the documentation, you can have Closure Compiler add the sourceMappingURL to the bottom of the script with something like this:
--output_wrapper "%output%
//# sourceMappingURL=output.js.map"
being added to your call. Not that you cannot use "\n" here, and you need a newline literal. On a Linux shell this works just fine (if you're inside of quotes when you press enter, the command doesn't get executed).