-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
52 lines (44 loc) · 1.25 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs-extra')
const chalk = require('chalk')
const execa = require('execa')
const { gzipSync } = require('zlib')
const { compress } = require('brotli')
const files = [
'dist/vuex-orm-apollo.esm-browser.js',
'dist/vuex-orm-apollo.esm-browser.prod.js',
'dist/vuex-orm-apollo.esm-bundler.js',
'dist/vuex-orm-apollo.global.js',
'dist/vuex-orm-apollo.global.prod.js',
'dist/vuex-orm-apollo.cjs.js'
]
async function run() {
await build()
checkAllSizes()
generateApiDocs()
}
async function build() {
await fs.remove('dist')
await execa('rollup', ['-c', 'rollup.config.js'], { stdio: 'inherit' })
}
function checkAllSizes() {
console.log()
files.map((f) => checkSize(f))
console.log()
}
function checkSize(file) {
const f = fs.readFileSync(file)
const minSize = (f.length / 1024).toFixed(2) + 'kb'
const gzipped = gzipSync(f)
const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
const compressed = compress(f)
const compressedSize = (compressed.length / 1024).toFixed(2) + 'kb'
console.log(
`${chalk.gray(
chalk.bold(file)
)} size:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
)
}
async function generateApiDocs() {
await execa('yarn', ['build:dts'], { stdio: 'inherit' })
}
run()