Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lydonchandra/b97b38e3ff56ba8e0ba5 to your computer and use it in GitHub Desktop.
Save lydonchandra/b97b38e3ff56ba8e0ba5 to your computer and use it in GitHub Desktop.
REM --source_map_location_mapping is case SENSITIVE !
REM need extra escaped double quote --source_map_location_mapping="\"C:/tools/closure/^|http://bla/\"" as per http://stackoverflow.com/a/29542669
java -jar compiler.jar --compilation_level=SIMPLE_OPTIMIZATIONS --create_source_map=C:\tools\closure\latest\maplayer.js.map --output_wrapper "%output%//# sourceMappingURL=maplayer.js.map" --js=C:\tools\closure\mapslayer.js --js_output_file=maplayer.min.js --source_map_location_mapping="\"C:/tools/closure/^|http://bla/\""
@lydonchandra
Copy link
Author

--source_map_location_mapping=""C:/tools/closure/^|http://bla/\"" needs extra and espaced double quote "

@lydonchandra
Copy link
Author

Only found this out after reading SourceMap.java (in closure compiler source code)
(https://github.com/google/closure-compiler/blob/v20150609/src/com/google/javascript/jscomp/SourceMap.java#L140)

private String fixupSourceLocation(String sourceFile) {
// Replace backslashes (the file separator used on Windows systems).
if (File.separatorChar == '\\') {
  sourceFile = sourceFile.replace('\\', '/');
}

if (prefixMappings.isEmpty()) {
  return sourceFile;
}

String fixed = sourceLocationFixupCache.get(sourceFile);
if (fixed != null) {
  return fixed;
}

// Replace the first prefix found with its replacement
for (LocationMapping mapping : prefixMappings) {
  if (sourceFile.startsWith(mapping.prefix)) {
    fixed = mapping.replacement + sourceFile.substring(
      mapping.prefix.length());
    break;
  }
}

// If none of the mappings match then use the original file path.
if (fixed == null) {
  fixed = sourceFile;
}

sourceLocationFixupCache.put(sourceFile, fixed);
return fixed;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment