Chrome canary & source maps

846 views
Skip to first unread message

Johannes Nel

unread,
Mar 10, 2012, 4:54:31 PM3/10/12
to closure-comp...@googlegroups.com
Hi

I was just watching the g+ video on chrome tools (yay for some of the things they are doing) when source maps came up, a developer asked if source maps would work with advanced compilation, Paul Irish said yes but proceeded to show a simple compilation script. Can someone on the closure team tell me wether this feature will work (and also if source maps will be available for our gss compilation as well).


The video (i can recommend it).

Johan

--
j:pn
\\no comment

John Lenz

unread,
Mar 10, 2012, 8:54:13 PM3/10/12
to closure-comp...@googlegroups.com
Yep, the compiler tries to track the source of every AST node through every optimization and does a good job of it IMHO so it works with any set of optimization options including ADVANCED.

I don't know of any attempt to generate source maps for GSS or to support it in Chrome.

Guido Tapia

unread,
Mar 11, 2012, 10:35:52 PM3/11/12
to closure-comp...@googlegroups.com
I just tried this and it works great in canary and dev channel (havent tried others).  Just add this comment to the end of your compiled file:

//@ sourceMappingURL=src/source-ma­p-location.js 

Tnx

John Lenz

unread,
Mar 12, 2012, 1:38:28 AM3/12/12
to closure-comp...@googlegroups.com
I wonder if we should add a option to add it as part of the compiler's build.  Something like: 
  --source_map_serving_prefix=src/

Johannes Nel

unread,
Mar 12, 2012, 2:31:16 AM3/12/12
to closure-comp...@googlegroups.com
>>I wonder if we should add a option to add it as part of the compiler's build.  Something like: 
  --source_map_serving_prefix=src/

yes, and support multiple source paths please.

John Lenz

unread,
Mar 12, 2012, 1:46:12 PM3/12/12
to closure-comp...@googlegroups.com

Can you be more specific which path?

Guido Tapia

unread,
Mar 12, 2012, 6:40:11 PM3/12/12
to closure-comp...@googlegroups.com
John, 

To be honest when I added: 'create_source_map' and 'source_map_format=V3' I secretly hoped that the  //@ sourceMappingURL=src/source-ma­p-location.js  line was added automatically to my compiled file as then I would not have had to do it manually in my build script.

Is there a way for the compiler to work out the path for the sourceMappingURL based on the path between the output_file and create_source_map parameters?

Anyways, this is a super cool feature as the old source map plugin was such a pain (and rarely worked for me really).

John Lenz

unread,
Mar 12, 2012, 6:56:42 PM3/12/12
to closure-comp...@googlegroups.com
Can you give an example of what you are hoping for?  If I can make it the override-able default I will.  I know that some have found using the HTTP header more convenient than modifying the compiler's output.

Guido Tapia

unread,
Mar 12, 2012, 7:44:48 PM3/12/12
to closure-comp...@googlegroups.com
Hi John,

Lets say I'm compiling with the following settings (using closurebuilder syntax):
--compiler_flags="--create_source_map=scripts\src\scripts.source.map.js" ^
--compiler_flags="--source_map_format=V3" ^
--output_file=scripts\script.min.js && ^

Then I would really like to see the 'script.min.js' file end with the line:
//@ sourceMappingURL=src/scripts.source.map.js 

I.e. The compiler was smart enough to work out the relative path from scripts\script.min.js to scripts\src\scripts.source.map.js.  

Again, this is just for convenience as manually adding this is not a problem. Also, I'm not really sure whether this would be the compiler or closurebuilder.py as looking at it now the output_file param is for closurebuilder not the compiler.

Tnx

John Lenz

unread,
Jun 7, 2013, 1:40:42 PM6/7/13
to closure-compiler

Just an FYI. The source map spec now prefers //# rather than //@ due to a conflict with IEs conditional code support. FF and Chrome should both support this in a couple of months as the support has been added to their code bases.

On Jun 7, 2013 8:30 AM, <rwbla...@gmail.com> wrote:
I actually added this to my source file:
/** @preserve
//@ sourceMappingURL=src/scripts.source.map.js 
**/

It seemed to work. I've only done this in one project, so I can't say if it will always work,and there may be cleaner options. But this seemed to do the trick for me. 
--
 
---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-d...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages