-
Notifications
You must be signed in to change notification settings - Fork 335
/
esbuild.js
62 lines (57 loc) · 1.63 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//@ts-check
const esbuild = require('esbuild');
/**
* @typedef {import('esbuild').BuildOptions} BuildOptions
*/
/** @type BuildOptions */
const clientOptions = {
bundle: true,
external: ['vscode'],
target: 'ES2022',
platform: 'node',
sourcemap: false,
entryPoints: ['client/src/extension.ts'],
outfile: 'client/out/extension.js',
preserveSymlinks: true,
format: 'cjs',
};
/** @type BuildOptions */
const serverOptions = {
bundle: true,
target: 'ES2022',
platform: 'node',
sourcemap: false,
entryPoints: ['server/src/eslintServer.ts'],
outfile: 'server/out/eslintServer.js',
preserveSymlinks: true,
format: 'cjs',
};
function createContexts() {
return Promise.all([
esbuild.context(clientOptions),
esbuild.context(serverOptions),
]);
}
createContexts().then(contexts => {
if (process.argv[2] === '--watch') {
const promises = [];
for (const context of contexts) {
promises.push(context.watch());
}
return Promise.all(promises).then(() => { return undefined; });
} else {
const promises = [];
for (const context of contexts) {
promises.push(context.rebuild());
}
Promise.all(promises).then(async () => {
for (const context of contexts) {
await context.dispose();
}
}).then(() => { return undefined; }).catch(console.error);
}
}).catch(console.error);