build-css.js 1.8 KB

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