build.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const fs = require('fs-extra')
  2. const chalk = require('chalk')
  3. const execa = require('execa')
  4. const { gzipSync } = require('zlib')
  5. const { compress } = require('brotli')
  6. const files = [
  7. 'dist/vuex.esm-browser.js',
  8. 'dist/vuex.esm-browser.prod.js',
  9. 'dist/vuex.esm-bundler.js',
  10. 'dist/vuex.global.js',
  11. 'dist/vuex.global.prod.js',
  12. 'dist/vuex.cjs.js'
  13. ]
  14. async function run() {
  15. await Promise.all([build(), copy()])
  16. checkAllSizes()
  17. }
  18. async function build() {
  19. await execa('rollup', ['-c', 'rollup.config.js'], { stdio: 'inherit' })
  20. }
  21. async function copy() {
  22. await fs.copy('src/index.mjs', 'dist/vuex.mjs')
  23. }
  24. function checkAllSizes() {
  25. console.log()
  26. files.map((f) => checkSize(f))
  27. console.log()
  28. }
  29. function checkSize(file) {
  30. const f = fs.readFileSync(file)
  31. const minSize = (f.length / 1024).toFixed(2) + 'kb'
  32. const gzipped = gzipSync(f)
  33. const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
  34. const compressed = compress(f)
  35. const compressedSize = (compressed.length / 1024).toFixed(2) + 'kb'
  36. console.log(
  37. `${chalk.gray(
  38. chalk.bold(file)
  39. )} size:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
  40. )
  41. }
  42. run()