-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathesbuild.mjs
More file actions
30 lines (27 loc) · 886 Bytes
/
esbuild.mjs
File metadata and controls
30 lines (27 loc) · 886 Bytes
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
import fs from 'fs';
import * as esbuild from 'esbuild';
const loadJSON = (path) => JSON.parse(fs.readFileSync(new URL(path, import.meta.url)));
const data = loadJSON('package.json');
const options = {
entryPoints: ['src/index.ts'],
bundle: true,
minify: process.env.NODE_ENV !== 'development',
sourcemap: process.env.NODE_ENV === 'development',
mainFields: ['module', 'main'],
external: ['coc.nvim'],
platform: 'node',
target: 'node18',
outfile: data.main,
// https://esbuild.github.io/api/#log-level
logLevel: process.env.NODE_ENV === 'development' ? 'info' : 'error',
};
if (process.argv.length > 2 && process.argv[2] === '--watch') {
const ctx = await esbuild.context(options);
await ctx.watch();
console.log('watching...');
} else {
const result = await esbuild.build(options);
if (result.errors.length) {
console.error(result.errors);
}
}