-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
55 lines (50 loc) · 1.44 KB
/
esbuild.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
/* eslint-disable @typescript-eslint/no-var-requires */
const chokidar = require('chokidar')
const esbuild = require('esbuild')
const child_process = require('child_process')
const rimraf = require('rimraf')
async function start() {
esbuild
.build({
entryPoints: ['src/index.ts'],
bundle: true,
minify: process.env.NODE_ENV === 'production',
sourcemap: process.env.NODE_ENV === 'development',
mainFields: ['module', 'main'],
external: ['coc.nvim', 'pretty-ts-errors-markdown'],
platform: 'node',
target: 'node14.14',
outfile: 'node_modules/.esbuild-cache/build/index.js',
plugins: [],
})
.catch((e) => {
console.error(e)
})
.then(() => {
try {
child_process.execSync(
'rsync -avz --delete ./node_modules/.esbuild-cache/build ./',
)
console.log('rsync completed successfully.')
} catch (error) {
console.error('Error occurred while running rsync:', error.message)
}
})
}
function deleteBuild() {
return rimraf.sync('./node_modules/.esbuild-cache/build')
}
deleteBuild()
start()
if (process.argv.length > 2 && process.argv[2] === '--watch') {
const watcher = chokidar.watch(['src/**/*.*', 'yalc.lock'], {
ignoreInitial: true,
})
;['change', 'add', 'unlink'].forEach((event) => {
watcher.on(event, (path) => {
console.log(`File ${event}: ${path}`)
deleteBuild()
start()
})
})
}