build-css.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var sass = require('node-sass')
  2. var postcss = require('postcss')
  3. var autoprefixer = require('autoprefixer')
  4. var cssnano = require('cssnano')
  5. var safeImportant = require('postcss-safe-important')
  6. var chalk = require('chalk')
  7. var fs = require('fs')
  8. var path = require('path')
  9. var mkdirp = require('mkdirp')
  10. mkdirp.sync('./dist/')
  11. function handleErr (err) {
  12. console.error(chalk.red('✗ Error:'), chalk.red(err.message))
  13. }
  14. function minifyCSS () {
  15. return new Promise(function (resolve) {
  16. fs.readFile('./dist/uppy.css', function (err, css) {
  17. if (err) handleErr(err)
  18. postcss([ cssnano ])
  19. .process(css, { from: path.join(__dirname, '../dist/uppy.css') })
  20. .then(function (postCSSResult) {
  21. postCSSResult.warnings().forEach(function (warn) {
  22. console.warn(warn.toString())
  23. })
  24. fs.writeFile('./dist/uppy.min.css', postCSSResult.css, function (err) {
  25. if (err) handleErr(err)
  26. console.info(chalk.green('✓ Minified Bundle CSS:'), chalk.magenta('uppy.min.css'))
  27. resolve()
  28. })
  29. })
  30. .catch(err => handleErr(err))
  31. })
  32. })
  33. }
  34. function compileCSS () {
  35. return new Promise(function (resolve) {
  36. sass.render({file: './src/scss/uppy.scss'}, function (err, sassResult) {
  37. if (err) handleErr(err)
  38. postcss([ autoprefixer, safeImportant ])
  39. .process(sassResult.css, { from: path.join(__dirname, '../src/scss/uppy.scss') })
  40. .then(function (postCSSResult) {
  41. postCSSResult.warnings().forEach(function (warn) {
  42. console.warn(warn.toString())
  43. })
  44. fs.writeFile('./dist/uppy.css', postCSSResult.css, function (err) {
  45. if (err) handleErr(err)
  46. console.info(chalk.green('✓ Built Uppy CSS:'), chalk.magenta('uppy.css'))
  47. resolve()
  48. })
  49. })
  50. .catch(err => handleErr(err))
  51. })
  52. })
  53. }
  54. compileCSS()
  55. .then(minifyCSS)
  56. .then(function () {
  57. console.info(chalk.yellow('✓ CSS Bundle 🎉'))
  58. })
  59. .catch(err => handleErr(err))