fis-optimizer-uglify-js
Advanced tools
Comparing version 0.1.3 to 0.1.4
91
index.js
@@ -10,84 +10,37 @@ /* | ||
// 直接将源码嵌入到 map 表的版本,但是,似乎 chrome 不支持,先备份! | ||
// module.exports = function(content, file, conf){ | ||
module.exports = function(content, file, conf){ | ||
// var mapping = fis.file.wrap(file.dirname + '/' + file.filename + '.map'); | ||
var mapping = fis.file.wrap(file.dirname + '/' + file.filename + '.map'); | ||
// conf.fromString = true; | ||
// conf.outSourceMap = file.basename; | ||
// var ret = UglifyJS.minify(content, conf); | ||
// mapping.useDomain = true; | ||
// var mapData = JSON.parse(ret.map); | ||
// mapData.sources = [file.basename]; | ||
// mapData.sourcesContent = [content]; | ||
// var newData = { | ||
// version: mapData.version, | ||
// file: mapData.file, | ||
// sourceRoot: mapData.sourceRoot || "", | ||
// sources: mapData.sources, | ||
// sourcesContent: mapData.sourcesContent, | ||
// names: mapData.names, | ||
// mappings: mapData.mappings | ||
// }; | ||
// mapping.setContent(JSON.stringify(newData)); | ||
// file.extras = file.extras || {}; | ||
// file.extras.derived = file.extras.derived || []; | ||
// file.extras.derived.push(mapping); | ||
// ret.code += '\n//# sourceMappingURL={{path:'+mapping.subpath + '}}\n'; | ||
// return ret.code; | ||
// }; | ||
module.exports = function(content, file, conf) { | ||
conf.fromString = true; | ||
conf.outSourceMap = file.filename + '.org' + file.rExt; | ||
if (conf.sourceMap) { | ||
var mapping = fis.file.wrap(file.dirname + '/' + file.filename + '.map'); | ||
var ret = UglifyJS.minify(content, conf); | ||
mapping.useDomain = true; | ||
mapping.useDomain = true; | ||
mapping.useHash = true; | ||
// chrome 不支持 sourcesContent 所以还需要一份源码。 | ||
var source = fis.file.wrap(file.dirname + '/' + file.filename + '-original' + file.rExt); | ||
var mapData = JSON.parse(ret.map); | ||
source.setContent(content); | ||
mapData.sources = [mapData.file]; | ||
mapData.sourcesContent = [content]; | ||
conf.outSourceMap = file.basename; | ||
} | ||
var newData = { | ||
version: mapData.version, | ||
file: mapData.file, | ||
sources: mapData.sources, | ||
sourcesContent: mapData.sourcesContent, | ||
names: mapData.names, | ||
mappings: mapData.mappings | ||
}; | ||
var ret = UglifyJS.minify(content, conf); | ||
mapping.setContent(JSON.stringify(newData)); | ||
if (conf.sourceMap) { | ||
var mapData = JSON.parse(ret.map); | ||
file.extras = file.extras || {}; | ||
file.extras.derived = file.extras.derived || []; | ||
file.extras.derived.push(mapping); | ||
mapData.sources = ['{{url:'+source.subpath+'}}']; | ||
ret.code += '\n//# sourceMappingURL={{url:'+mapping.subpath + '}}\n'; | ||
// 排一下顺序! | ||
var newData = { | ||
version: mapData.version, | ||
file: mapData.file, | ||
sourceRoot: mapData.sourceRoot || "", | ||
sources: mapData.sources, | ||
names: mapData.names, | ||
mappings: mapData.mappings | ||
}; | ||
mapping.setContent(JSON.stringify(newData)); | ||
file.extras = file.extras || {}; | ||
file.extras.derived = file.extras.derived || []; | ||
file.extras.derived.push(mapping); | ||
file.extras.derived.push(source); | ||
ret.code += '\n//# sourceMappingURL={{url:'+mapping.subpath + '}}\n'; | ||
} | ||
return ret.code; | ||
}; |
{ | ||
"name" : "fis-optimizer-uglify-js", | ||
"description" : "A optimizer for fis to compress js by using uglify-js.", | ||
"version" : "0.1.3", | ||
"version" : "0.1.4", | ||
"author" : "FIS Team <fis@baidu.com>", | ||
@@ -6,0 +6,0 @@ "homepage" : "http://fis.baidu.com/", |
3446
30