diff options
author | pengzhenqing <pengzhenqing@sensetime.com> | 2016-10-09 14:15:25 +0800 |
---|---|---|
committer | Richard van Velzen <rvanvelzen1@gmail.com> | 2016-10-23 21:21:39 +0200 |
commit | e51c6ba38014fc73a4804a69c556d96f777bc0b3 (patch) | |
tree | 6313e745cf0d054514fd4ac201e23885576c1419 /tools | |
parent | 6389e52305f0d2e75a7bc6f8703c8d163d04cb99 (diff) | |
download | tracifyjs-e51c6ba38014fc73a4804a69c556d96f777bc0b3.tar.gz tracifyjs-e51c6ba38014fc73a4804a69c556d96f777bc0b3.zip |
Add an option for writing inline source map
Diffstat (limited to 'tools')
-rw-r--r-- | tools/node.js | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/node.js b/tools/node.js index 6712ccf6..a16169b1 100644 --- a/tools/node.js +++ b/tools/node.js @@ -44,6 +44,7 @@ exports.minify = function(files, options) { sourceRoot : null, inSourceMap : null, sourceMapUrl : null, + sourceMapInline : false, fromString : false, warnings : false, mangle : {}, @@ -117,7 +118,7 @@ exports.minify = function(files, options) { if (typeof options.inSourceMap == "string") { inMap = JSON.parse(fs.readFileSync(options.inSourceMap, "utf8")); } - if (options.outSourceMap) { + if (options.outSourceMap || options.sourceMapInline) { output.source_map = UglifyJS.SourceMap({ file: options.outSourceMap, orig: inMap, @@ -138,16 +139,19 @@ exports.minify = function(files, options) { var stream = UglifyJS.OutputStream(output); toplevel.print(stream); - var mappingUrlPrefix = "\n//# sourceMappingURL="; - if (options.outSourceMap && typeof options.outSourceMap === "string" && options.sourceMapUrl !== false) { - stream += mappingUrlPrefix + (typeof options.sourceMapUrl === "string" ? options.sourceMapUrl : options.outSourceMap); - } var source_map = output.source_map; if (source_map) { source_map = source_map + ""; } + var mappingUrlPrefix = "\n//# sourceMappingURL="; + if (options.sourceMapInline) { + stream += mappingUrlPrefix + "data:application/json;charset=utf-8;base64," + new Buffer(source_map).toString("base64"); + } else if (options.outSourceMap && typeof options.outSourceMap === "string" && options.sourceMapUrl !== false) { + stream += mappingUrlPrefix + (typeof options.sourceMapUrl === "string" ? options.sourceMapUrl : options.outSourceMap); + } + return { code : stream + "", map : source_map |