1 Star 0 Fork 13

gjTool/robot-tools

forked from vnool/robot-tools 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
plugins.static.js 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
yooge 提交于 2020-11-23 02:10 +08:00 . first commit
'use strict';
//https://www.npmjs.com/package/uglify-js
//var UglifyJS = require("uglify-js");
//https: //github.com/mishoo/UglifyJS/tree/harmony
var FS = require("fs");
var UglifyJS = require("uglify-es");
var options_ = {
mangle: {
toplevel: true,
},
nameCache: {}
};
module.exports = {
apply(compiler) {
compiler.hooks.emit.tap('compilation', compilation => {
//不删除plugins
// if (!(process.argv && process.argv.indexOf('--no-plugins') > -1)) {
// return;
// }
// if (process.env.NODE_ENV != 'production') {
// console.log('不压缩');
// return;
// }
var allcode = {};
// 遍历所有资源文件
for (let filePathName in compilation.assets) {
if (filePathName.substr(filePathName.length - 3) == '.js' && filePathName.indexOf('/robots/') > 0) {
//
;; ///good
} else {
console.log('忽略2:' + filePathName);
continue;
}
let content = compilation.assets[filePathName].source() || '';
content = content.toString('utf-8');
/* 压缩 */
var result = UglifyJS.minify(content);
if (result.error != undefined) {
console.log('忽略:' + filePathName);
console.log(result.error); // runtime error, or `undefined` if no error
} else {
console.log(filePathName);
content = result.code;
//content = RSA.encode(content);
}
// 重写指定输出模块内容
compilation.assets[filePathName] = {
source() {
return content;
},
size() {
return content.length;
}
};
} //for
});
},
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/gjTool/robot-tools.git
git@gitee.com:gjTool/robot-tools.git
gjTool
robot-tools
robot-tools
main

搜索帮助