js代码发布的时候需要去除注释,总算找到一个比较好用的js库
参考decomment
npm install decomment
编写一个js脚本remove-comments.js,内容如下:
const fs = require('fs');
const path = require('path');
const process = require('process');
const decomment = require('decomment');
let sourceFile = process.argv[2];
let targetFile = process.argv[3];
if (!sourceFile || !targetFile) {
throw new Error('Please set source file and target file.');
}
sourceFile = path.resolve(__dirname, sourceFile);
targetFile = path.resolve(__dirname, targetFile);
fs.readFile(sourceFile, 'utf8', (err, data) => {
if (err) throw err;
fs.writeFile(targetFile, decomment(data), 'utf8', (err, data) => {
if (err) throw err;
console.log('Remove Comments Done!');
});
});
只需要在命令行下执行:
node remove-comments.js invoice.js invoice_remove.js
invoice_remove.js就是删除注释的代码
网友评论