minify-js.js 472 B

123456789101112131415161718
  1. const fs = require('fs');
  2. const path = require('path');
  3. const {minify} = require('uglify-es');
  4. const distDir = `${path.dirname(__dirname)}/dist/js`;
  5. const files = ['datepicker', 'datepicker-full'];
  6. files.forEach((basename) => {
  7. const fileNameBase = `${distDir}/${basename}`;
  8. const file = fs.readFileSync(`${fileNameBase}.js`, 'utf8');
  9. const {code, error} = minify(file);
  10. if (error) {
  11. throw error;
  12. }
  13. fs.writeFileSync(`${fileNameBase}.min.js`, code);
  14. });