-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
buildTsPlugin.mjs
53 lines (50 loc) · 1.48 KB
/
buildTsPlugin.mjs
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
//@ts-check
import buildTsPlugin from '@zardoy/vscode-utils/build/buildTypescriptPlugin.js'
import { build, analyzeMetafile } from 'esbuild'
import fs from 'fs'
const enableWatch = process.argv.includes('--watch')
await build({
bundle: true,
external: ['typescript-essential-plugins'],
// minify: !watch,
watch: enableWatch,
entryPoints: ['./typescript/src/volarConfig.ts'],
outfile: './out/volarConfig.js',
format: 'cjs',
logLevel: 'info',
platform: 'node',
// banner: {
// js: 'let ts, tsFull;',
// },
// treeShaking: true,
})
const result = await buildTsPlugin('typescript', undefined, undefined, {
minify: !enableWatch,
metafile: true,
define: {
'import.meta': '{}',
},
banner: {
js: 'let ts, tsFull;',
// js: 'const log = (...args) => console.log(...args.map(a => JSON.stringify(a)))',
},
external: ['perf_hooks'],
plugins: [
{
name: 'watch-notifier',
setup(build) {
const writeStatus = (/** @type {number} */ signal) => {
fs.writeFileSync('./out/build_plugin_result', signal.toString())
}
build.onStart(() => {
writeStatus(0)
})
build.onEnd(({ errors }) => {
writeStatus(errors.length ? 2 : 1)
})
},
},
],
})
// @ts-ignore
// console.log(await analyzeMetafile(result.metafile))