minify-css.js 759 B

12345678910111213141516171819202122232425262728293031
  1. const fs = require('fs');
  2. const path = require('path');
  3. const postcss = require('postcss');
  4. const cssnano = require('cssnano');
  5. const distDir = `${path.dirname(__dirname)}/dist/css`;
  6. const files = [
  7. 'datepicker',
  8. 'datepicker-bulma',
  9. 'datepicker-bs4',
  10. 'datepicker-foundation',
  11. ];
  12. Promise.all(files.map((basename) => {
  13. return new Promise((resolve) => {
  14. const fileNameBase = `${distDir}/${basename}`;
  15. const from = `${fileNameBase}.css`;
  16. const file = fs.readFileSync(from, 'utf8');
  17. postcss([cssnano])
  18. .process(file, {from, map: false})
  19. .then((result) => {
  20. fs.writeFileSync(`${fileNameBase}.min.css`, result.css);
  21. resolve();
  22. })
  23. .catch((err) => {
  24. console.error(err);
  25. });
  26. });
  27. }));