builder.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2020/2/19
  7. * @version
  8. */
  9. const Uglyfy = require('uglify-es');
  10. const fs = require('fs');
  11. const path = require('path');
  12. const filePath = path.join(__dirname, 'app', 'public', 'js'); // __dirname + '/app/public/js';
  13. const filter = ['base_path_tree.js', 'export_excel.js', 'spreadjs_zh.js', 'project_chapter.js', 'deal_pay.js'];
  14. fs.readdir(filePath, function (err, files) {
  15. if (err) {
  16. console.warn(err);
  17. } else {
  18. for (const f of files) {
  19. if (filter.indexOf(f) <= 0) continue;
  20. const file = filePath + '/' + f;
  21. if (file.indexOf('.min.') >= 0) continue;
  22. fs.stat(file, function (err, stats) {
  23. const fileInfo = path.parse(file);
  24. if (!err) {
  25. if (stats.isFile()) {
  26. const code = fs.readFileSync(file, 'utf8');
  27. fs.writeFileSync(path.join(fileInfo.dir, fileInfo.name + '.min.js'), Uglyfy.minify(code, {mangle: true}).code);
  28. }
  29. }
  30. });
  31. }
  32. }
  33. });