'use strict'; /** * * * @author Mai * @date * @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'; fs.readdir(filePath, function (err, files) { if (err) { console.warn(err) } else { for (const f of files) { 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); } } }); } } });