diff options
author | Artemy Tregubenko <me@arty.name> | 2014-01-09 15:12:00 +0100 |
---|---|---|
committer | Artemy Tregubenko <me@arty.name> | 2014-01-09 15:12:00 +0100 |
commit | 03cf94ebe8b7bc87eccde800705beabf012ff275 (patch) | |
tree | 226c23d1f3a679f3ce0d3678dcbe6249ce9187e6 | |
parent | c3087dd179bcef93626ae8227bf8f0ac5baa15a2 (diff) | |
download | tracifyjs-03cf94ebe8b7bc87eccde800705beabf012ff275.tar.gz tracifyjs-03cf94ebe8b7bc87eccde800705beabf012ff275.zip |
Added support for sourcesContent property of source map
-rw-r--r-- | README.md | 4 | ||||
-rwxr-xr-x | bin/uglifyjs | 13 | ||||
-rw-r--r-- | tools/node.js | 10 |
3 files changed, 26 insertions, 1 deletions
@@ -54,6 +54,10 @@ The available options are: --source-map-url The path to the source map to be added in //# sourceMappingURL. Defaults to the value passed with --source-map. [string] + --source-map-include-sources + Pass this flag if you want to include the content of + source files in the source map as sourcesContent + property. [boolean] --in-source-map Input source map, useful if you're compressing JS that was generated from some other original code. --screw-ie8 Pass this flag if you don't care about full compliance diff --git a/bin/uglifyjs b/bin/uglifyjs index 4ffbeffd..3a3318b2 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -22,6 +22,7 @@ mangling you need to use `-c` and `-m`.\ .describe("source-map", "Specify an output file where to generate source map.") .describe("source-map-root", "The path to the original source to be included in the source map.") .describe("source-map-url", "The path to the source map to be added in //# sourceMappingURL. Defaults to the value passed with --source-map.") + .describe("source-map-include-sources", "Pass this flag if you want to include the content of source files in the source map as sourcesContent property.") .describe("in-source-map", "Input source map, useful if you're compressing JS that was generated from some other original code.") .describe("screw-ie8", "Pass this flag if you don't care about full compliance with Internet Explorer 6-8 quirks (by default UglifyJS will try to be IE-proof).") .describe("expr", "Parse a single expression, rather than a program (for parsing JSON)") @@ -88,6 +89,7 @@ You need to pass an argument to this option to specify the name that your module .string("p") .boolean("expr") + .boolean("source-map-include-sources") .boolean("screw-ie8") .boolean("export-all") .boolean("self") @@ -218,6 +220,7 @@ var STATS = {}; var OUTPUT_FILE = ARGS.o; var TOPLEVEL = null; var P_RELATIVE = ARGS.p && ARGS.p == "relative"; +var SOURCES_CONTENT = {}; var SOURCE_MAP = ARGS.source_map ? UglifyJS.SourceMap({ file: P_RELATIVE ? path.relative(path.dirname(ARGS.source_map), OUTPUT_FILE) : OUTPUT_FILE, @@ -255,6 +258,7 @@ async.eachLimit(files, 1, function (file, cb) { } } } + SOURCES_CONTENT[file] = code; time_it("parse", function(){ if (ARGS.spidermonkey) { var program = JSON.parse(code); @@ -337,6 +341,15 @@ async.eachLimit(files, 1, function (file, cb) { if (MANGLE) time_it("mangle", function(){ TOPLEVEL.mangle_names(MANGLE); }); + + if (ARGS.source_map_include_sources) { + for (var file in SOURCES_CONTENT) { + if (SOURCES_CONTENT.hasOwnProperty(file)) { + SOURCE_MAP.get().setSourceContent(file, SOURCES_CONTENT[file]); + } + } + } + time_it("generate", function(){ TOPLEVEL.print(output); }); diff --git a/tools/node.js b/tools/node.js index 7e6a38df..4dfa9338 100644 --- a/tools/node.js +++ b/tools/node.js @@ -64,7 +64,8 @@ exports.minify = function(files, options) { UglifyJS.base54.reset(); // 1. parse - var toplevel = null; + var toplevel = null, + sourcesContent = {}; if (options.spidermonkey) { toplevel = UglifyJS.AST_Node.from_mozilla_ast(files); @@ -75,6 +76,7 @@ exports.minify = function(files, options) { var code = options.fromString ? file : fs.readFileSync(file, "utf8"); + sourcesContent[file] = code; toplevel = UglifyJS.parse(code, { filename: options.fromString ? "?" : file, toplevel: toplevel @@ -110,6 +112,12 @@ exports.minify = function(files, options) { orig: inMap, root: options.sourceRoot }); + if (options.sourceMapIncludeSources) { + for (var file in sourcesContent) { + options.source_map.get().setSourceContent(file, sourcesContent[file]); + } + } + } if (options.output) { UglifyJS.merge(output, options.output); |