build-css.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const fs = require('fs');
  2. const path = require('path');
  3. const postcss = require('postcss');
  4. const nodeSass = require('postcss-node-sass')({
  5. outputStyle: 'expanded',
  6. });
  7. const autoprefixer = require('autoprefixer');
  8. const syntax = require('postcss-scss');
  9. const rootDir = path.dirname(__dirname);
  10. const srcDir = `${rootDir}/sass`;
  11. const distDir = `${rootDir}/dist/css`;
  12. const files = [
  13. {in: 'datepicker.scss', out: 'datepicker.css'},
  14. {in: 'index-bulma.scss', out: 'datepicker-bulma.css'},
  15. {in: 'index-bs4.scss', out: 'datepicker-bs4.css'},
  16. {in: 'index-foundation.scss', out: 'datepicker-foundation.css'},
  17. ];
  18. if (!fs.existsSync(distDir)) {
  19. fs.mkdirSync(distDir, {recursive: true});
  20. }
  21. Promise.all(files.map((entry) => {
  22. return new Promise((resolve) => {
  23. const from = `${srcDir}/${entry.in}`;
  24. const file = fs.readFileSync(from, 'utf8');
  25. postcss([nodeSass, autoprefixer])
  26. .process(file, {syntax, from, map: false})
  27. .then((result) => {
  28. fs.writeFileSync(`${distDir}/${entry.out}`, result.css);
  29. resolve();
  30. })
  31. .catch((err) => {
  32. console.error(err);
  33. });
  34. });
  35. }));