1
0

build.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. async function run(config, files) {
  7. await Promise.all([build(config), copy()])
  8. checkAllSizes(files)
  9. }
  10. async function build(config) {
  11. await execa('rollup', ['-c', config], { stdio: 'inherit' })
  12. }
  13. async function copy() {
  14. await fs.copy('src/index.mjs', 'dist/vuex.mjs')
  15. }
  16. function checkAllSizes(files) {
  17. console.log()
  18. files.map((f) => checkSize(f))
  19. console.log()
  20. }
  21. function checkSize(file) {
  22. const f = fs.readFileSync(file)
  23. const minSize = (f.length / 1024).toFixed(2) + 'kb'
  24. const gzipped = gzipSync(f)
  25. const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
  26. const compressed = compress(f)
  27. const compressedSize = (compressed.length / 1024).toFixed(2) + 'kb'
  28. console.log(
  29. `${chalk.gray(
  30. chalk.bold(file)
  31. )} size:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
  32. )
  33. }
  34. module.exports = { run }