build-css.js 1.7 KB

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