builder.js 937 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  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. fs.readdir(filePath, function (err, files) {
  14. if (err) {
  15. console.warn(err)
  16. } else {
  17. for (const f of files) {
  18. const file = filePath + '/' + f;
  19. if (file.indexOf('.min.') >= 0) continue;
  20. fs.stat(file, function (err, stats) {
  21. const fileInfo = path.parse(file);
  22. if (!err) {
  23. if (stats.isFile()) {
  24. const code = fs.readFileSync(file, 'utf8');
  25. fs.writeFileSync(path.join(fileInfo.dir, fileInfo.name + '.min.js'), Uglyfy.minify(code, {mangle: true}).code);
  26. }
  27. }
  28. });
  29. }
  30. }
  31. });