-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-extension.js
57 lines (50 loc) · 1.35 KB
/
build-extension.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
53
54
55
56
57
/* eslint-disable */
const fs = require('fs')
const esbuild = require('esbuild')
const { gzip } = require('zlib')
const pkg = require('../package.json')
async function main() {
if (fs.existsSync('./extension/dist')) {
fs.rmSync('./extension/dist', { recursive: true }, (e) => {
if (e) {
throw e
}
})
}
try {
const esmResult = esbuild.buildSync({
entryPoints: ['./extension/src/extension.ts'],
outdir: 'extension/dist/web',
minify: true,
bundle: true,
format: 'cjs',
target: 'es6',
define: {
'process.env.NODE_ENV': '"production"',
},
tsconfig: '../extension/tsconfig.json',
external: Object.keys(pkg.dependencies)
.concat(Object.keys(pkg.devDependencies))
.concat(['vscode'])
,
metafile: true,
})
let esmSize = 0
Object.values(esmResult.metafile.outputs).forEach((output) => {
esmSize += output.bytes
})
fs.readFile('./dist/web/index.js', (_err, data) => {
gzip(data, (_err, result) => {
console.log(
`✔ ${pkg.name}: Built pkg. ${(esmSize / 1000).toFixed(2)}kb (${(
result.length / 1000
).toFixed(2)}kb minified)`
)
})
})
} catch (e) {
console.log(`× ${pkg.name}: Build failed due to an error.`)
console.log(e)
}
}
main()