forked from neoclide/coc.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
executable file
·64 lines (60 loc) · 1.59 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
56
57
58
59
60
61
62
63
64
const cp = require('child_process')
const fs = require('fs')
const path = require('path')
let revision = ''
try {
let res = cp.execSync('git rev-parse HEAD', {encoding: 'utf8'})
revision = res.trim().slice(0, 10)
} catch (e) {
// ignore
}
let envPlugin = {
name: 'env',
setup(build) {
build.onResolve({filter: /\/appenders/}, args => {
let fullpath = path.join(args.resolveDir, args.path)
return {
path: path.relative(__dirname, fullpath).replace(/\\/g, '/'),
namespace: 'env-ns'
}
})
build.onLoad({filter: /^node_modules\/log4js\/lib\/appenders$/, namespace: 'env-ns'}, args => {
let content = fs.readFileSync(path.join(args.path, 'index.js'), 'utf8')
return {
contents: content.replace(/require\.main/g, '""'),
resolveDir: args.path
}
})
}
}
async function start(watch) {
await require('esbuild').build({
entryPoints: ['src/main.ts'],
bundle: true,
watch,
minify: process.env.NODE_ENV === 'production',
sourcemap: process.env.NODE_ENV === 'development',
define: {REVISION: '"' + revision + '"', ESBUILD: 'true'},
mainFields: ['module', 'main'],
platform: 'node',
target: 'node10.12',
outfile: 'build/index.js',
plugins: [envPlugin]
})
}
let watch = false
if (process.argv.length > 2 && process.argv[2] === '--watch') {
console.log('watching...')
watch = {
onRebuild(error) {
if (error) {
console.error('watch build failed:', error)
} else {
console.log('watch build succeeded')
}
},
}
}
start(watch).catch(e => {
console.error(e)
})