forked from eclipse-cdt-cloud/cdt-gdb-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-web.js
58 lines (54 loc) · 1.83 KB
/
build-web.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
/*********************************************************************
* Copyright (c) 2024 Renesas Electronics Corporation and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*********************************************************************/
// @ts-check
const esbuild = require('esbuild');
const path = require('node:path');
const { nodeExternalsPlugin } = require('esbuild-node-externals');
/** @typedef {import('esbuild').BuildOptions} BuildOptions */
const args = process.argv.slice(2);
const optionWatch = args.includes('--watch');
const optionNoMinify = args.includes('--no-minify');
const sourceFolder = path.join(__dirname, 'src');
const distFolder = path.join(__dirname, 'dist');
/** @type {BuildOptions[]} */
const buildConfigurations = [
{
target: ['es2015'],
platform: 'browser',
format: 'cjs',
minify: !optionNoMinify,
bundle: true,
sourcemap: true,
entryPoints: [path.join(sourceFolder, 'web.ts')],
outfile: path.join(distFolder, 'browser', 'web.js'),
mainFields: ['browser', 'modules', 'main'],
alias: {
os: 'os-browserify',
path: 'path-browserify',
stream: 'stream-browserify',
},
plugins: [nodeExternalsPlugin()],
},
];
if (optionWatch) {
(async function watch() {
await Promise.all([
...buildConfigurations.map((config) =>
esbuild.context(config).then((context) => context.watch())
),
]);
})();
} else {
(async function build() {
await Promise.all([
...buildConfigurations.map((config) => esbuild.build(config)),
]);
})();
}