diff options
author | Mihai Bazon <mihai@bazon.net> | 2014-01-26 10:15:24 +0200 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2014-01-26 10:15:24 +0200 |
commit | 1dd05f44eb2e7fd56ee7344ece8619619609a7b1 (patch) | |
tree | 042ab0772994955d39666b402774b913abcf9019 | |
parent | bf7b122ab2e5a7cb2f6c3f7fa798628345260c7c (diff) | |
parent | f6203bd5a8063a3af835603ce1959310f14f7f5e (diff) | |
download | tracifyjs-1dd05f44eb2e7fd56ee7344ece8619619609a7b1.tar.gz tracifyjs-1dd05f44eb2e7fd56ee7344ece8619619609a7b1.zip |
Merge branch 'sourcesContent' of https://github.com/arty-name/UglifyJS2 into arty-name-sourcesContent
-rw-r--r-- | README.md | 4 | ||||
-rwxr-xr-x | bin/uglifyjs | 13 | ||||
-rw-r--r-- | tools/node.js | 12 |
3 files changed, 28 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..bef296ea 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,14 @@ exports.minify = function(files, options) { orig: inMap, root: options.sourceRoot }); + if (options.sourceMapIncludeSources) { + for (var file in sourcesContent) { + if (sourcesContent.hasOwnProperty(file)) { + options.source_map.get().setSourceContent(file, sourcesContent[file]); + } + } + } + } if (options.output) { UglifyJS.merge(output, options.output); |