'use strict'; /** * * * @author Mai * @date 2020/2/19 * @version */ const Uglyfy = require('uglify-es'); const fs = require('fs'); const path = require('path'); const filePath = path.join(__dirname, 'app', 'public', 'js'); // __dirname + '/app/public/js'; const filter = ['base_path_tree.js', 'export_excel.js', 'spreadjs_zh.js', 'project_chapter.js', 'deal_pay.js']; fs.readdir(filePath, function (err, files) { if (err) { console.warn(err); } else { for (const f of files) { if (filter.indexOf(f) <= 0) continue; const file = filePath + '/' + f; if (file.indexOf('.min.') >= 0) continue; fs.stat(file, function (err, stats) { const fileInfo = path.parse(file); if (!err) { if (stats.isFile()) { const code = fs.readFileSync(file, 'utf8'); fs.writeFileSync(path.join(fileInfo.dir, fileInfo.name + '.min.js'), Uglyfy.minify(code, {mangle: true}).code); } } }); } } });