build-css.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. .catch(err => handleErr(err))
  30. })
  31. })
  32. }
  33. function compileCSS () {
  34. return new Promise(function (resolve) {
  35. sass.render({file: './src/scss/uppy.scss'}, function (err, sassResult) {
  36. if (err) handleErr(err)
  37. postcss([ autoprefixer ])
  38. .process(sassResult.css, { from: path.join(__dirname, '../src/scss/uppy.scss') })
  39. .then(function (postCSSResult) {
  40. postCSSResult.warnings().forEach(function (warn) {
  41. console.warn(warn.toString())
  42. })
  43. fs.writeFile('./dist/uppy.css', postCSSResult.css, function (err) {
  44. if (err) handleErr(err)
  45. console.info(chalk.green('✓ Built Uppy CSS:'), chalk.magenta('uppy.css'))
  46. resolve()
  47. })
  48. })
  49. .catch(err => handleErr(err))
  50. })
  51. })
  52. }
  53. compileCSS()
  54. .then(minifyCSS)
  55. .then(function () {
  56. console.info(chalk.yellow('✓ CSS Bundle 🎉'))
  57. })
  58. .catch(err => handleErr(err))