fis-optimizer-uglify-js
Advanced tools
Comparing version 0.1.2 to 0.1.3
83
index.js
@@ -10,5 +10,84 @@ /* | ||
module.exports = function(content, file, conf){ | ||
// 直接将源码嵌入到 map 表的版本,但是,似乎 chrome 不支持,先备份! | ||
// module.exports = function(content, file, conf){ | ||
// 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; | ||
return UglifyJS.minify(content, conf).code; | ||
if (conf.sourceMap) { | ||
var mapping = fis.file.wrap(file.dirname + '/' + file.filename + '.map'); | ||
mapping.useDomain = true; | ||
// chrome 不支持 sourcesContent 所以还需要一份源码。 | ||
var source = fis.file.wrap(file.dirname + '/' + file.filename + '-original' + file.rExt); | ||
source.setContent(content); | ||
conf.outSourceMap = file.basename; | ||
} | ||
var ret = UglifyJS.minify(content, conf); | ||
if (conf.sourceMap) { | ||
var mapData = JSON.parse(ret.map); | ||
mapData.sources = ['{{url:'+source.subpath+'}}']; | ||
// 排一下顺序! | ||
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.2", | ||
"version" : "0.1.3", | ||
"author" : "FIS Team <fis@baidu.com>", | ||
@@ -6,0 +6,0 @@ "homepage" : "http://fis.baidu.com/", |
# fis-optimizer-uglify-js | ||
A optimizer for fis to compress js by using uglify-js. | ||
A optimizer for fis to compress js by using uglify-js. | ||
## 使用 | ||
FIS内置 | ||
## 配置 | ||
在项目配置文件(默认fis-conf.js)配置 | ||
```javascript | ||
fis.config.set('settings.optimizer.uglify-js', option); | ||
``` | ||
eg: | ||
```javascript | ||
//export, module, require不压缩变量名 | ||
fis.config.set('settings.optimizer.uglify-js', { | ||
mangle: { | ||
except: 'exports, module, require, define' | ||
} | ||
}); | ||
//自动去除console.log等调试信息 | ||
fis.config.set('settings.optimizer.uglify-js', { | ||
compress : { | ||
drop_console: true | ||
} | ||
}); | ||
``` | ||
`option` 详细请参见 https://github.com/mishoo/UglifyJS2 |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
4918
63
36
0