Skip to content
This repository has been archived by the owner on Nov 23, 2018. It is now read-only.

Generate Source-Map w/ Closure Compiler #45

Closed
drublic opened this issue Mar 27, 2012 · 11 comments
Closed

Generate Source-Map w/ Closure Compiler #45

drublic opened this issue Mar 27, 2012 · 11 comments

Comments

@drublic
Copy link
Member

drublic commented Mar 27, 2012

Do you think it's useful and possible to integrate the building of a source-map for JS-Files with Closure Compiler as described over here?

I think this is very helpful for everyone using the Ant Build Script.

@paulirish
Copy link
Member

++

it'll need a fresh build of the closure compiler jar.. but dont see why not.

also you can now do inline base64 sourcemaps, fwiw.. http://trac.webkit.org/changeset/111389

@roblarsen
Copy link
Member

+++

I'm planning on playing catch up with issues here next week. I'm heading to India and there's only so much reading/sleeping I can do on the plane and in airports. I'll add this on the front of my queue since it's cool

@drublic
Copy link
Member Author

drublic commented Mar 29, 2012

Rob, I've already played around a little bit with it. Will see what I can do until next week. Nothing pushed yet, but it will appear here.
Have a good flight and a lot of fun (I was in India in January, it's beautiful :))

@roblarsen
Copy link
Member

Thanks! I'm really excited for the trip. Both to see India itself and then to meet a bunch of people. I'll be meeting many Indian Sapient colleagues in person for the first time and then will also be presenting to a bunch of people from outside Sapient so it will be a great intro to the tech community in the NCR region.

Definitely let me know how it goes with the feature.

@drublic
Copy link
Member Author

drublic commented Apr 1, 2012

After playing around a little bit yesterday I had the feeling I came up with the commits over here.
Problems I currently have: The file is not copied to the publish folder but remains in intermediate. Furthermore I had the impression that scripts are not concatenated correctly.

My test was: build from three scripts (plugins.js, somescript.js, script.js), all scripts were minified, somescript.js was not concatenated.
This may be because of changes I made or because of the new Closure Compiler version. I'll try to look into it again, but I wanted to share this so that you can look into it, if you want to.

@roblarsen
Copy link
Member

I started to look into this. We just solved the script concatenation holy grail, so I don't really want to revisit how we're doing it any time soon. This might be harder than just plugging in the latest version of Closure Compiler. The default way to generate one of these relies on concatenation in Closure Compiler. We're not doing that so... back to the drawing board. I really want this as a feature though so we'll have to sort it out somehow.

@roblarsen
Copy link
Member

Revisit.

@ghost ghost assigned roblarsen Jan 23, 2013
@roblarsen
Copy link
Member

Revisited.

So... this is weird and I don't have a straightforward answer. @drublic your code works and could be built off of except for one diabolical issue- the issue that has me stumped (so far.)

Your code:

<apply executable="java" parallel="false">
  <fileset dir="${dir.source}/${dir.js}" excludes="${file.js.bypass}, **/*.min.js" includes="**/*.js">
  <exclude name="${dir.js}/otherscripts-concat.js"/>
  <exclude name="${dir.js}/scripts-concat.js"/>
  </fileset>          
  <arg line="-jar"/>
  <arg path="./${dir.build.tools}/${tool.compiler}"/>
  <arg line="--js"/>
  <srcfile/>
  <arg line="--compilation_level" />
  <arg value="${scripts.compilation.level}" />
  <arg line="--warning_level" />
  <arg value="${scripts.compilation.warninglevel}" />
  <arg line="--create_source_map" />
   <arg value="${basedir}/${dir.intermediate}/${dir.js}/source_map.js.map" />
  <arg line="--source_map_format=V3"/>
  <arg line="--js_output_file" />
  <mapper type="glob" from="*.js" to="${basedir}/${dir.intermediate}/${dir.js}/*.js"/>
  <targetfile/>
</apply>

...creates a single map file source_map.js.map that maps to (in my testbed) plugins.js

my understanding is that it should produce one _.js.map file for _each* file in the directory so that every file is mapped to a corresponding source JS when people inspect the code. I think this would work correctly concatenated as long as the source files were available to browse on the server. The problem is, there's no way (that I've seen) to do the same kind of filename mapping seen in the <mapper> element as a value for the --create_source_map argument. You can't have multiple mappers in an <apply> and I've tried some tricks with outputting things to stdout and using a <redirector> to send it to a properly mapped file (which in effect allows for two <mappers> per <apply>. that didn't work. I'd really like to get this in, but I'm not sure how to do it just yet.

Dear Github people, I am open to suggestions.

@roblarsen
Copy link
Member

Updating: Unless someone else comes in with a heroic pull request I'm pushing this out to a later release. I can do this using the <for> task and the list generated by the findAttribute class, but it will take some surgery on the whole minification and concatenation workflow. I will also need to make it configurable. It's going to take a little planning and there's not guarantee that it's going to work the way I expect so I'm pushing it out.

Still holding out hope for a hero :)

@thanpolas
Copy link

so that every file is mapped to a corresponding source JS when people inspect the code

@roblarsen do you eventually concatenate the minified files for which a mapsource has been produced? I am having a problem when doing that as the sourcemaps become invalid for the produced concatenated file...

irrelevant: i guess you don't consider integrating grunt ha?

@roblarsen
Copy link
Member

old... and I'm not going to revisit this myself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants