-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.mjs
74 lines (64 loc) · 1.72 KB
/
build.mjs
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
65
66
67
68
69
70
71
72
73
74
'use strict'
import { build, context } from 'esbuild'
import cssModules from 'esbuild-css-modules-plugin'
import path from 'path'
const prod = process.env.NODE_ENV === 'production'
/** @type {import('esbuild').BuildOptions} */
const base = {
bundle: true,
dropLabels: prod ? ['DEBUG'] : [],
format: 'cjs',
mainFields: ['module', 'main'],
minify: prod,
plugins: [
cssModules({
generateScopedName: function (name, filename, css) {
var i = css.indexOf('.' + name)
var line = css.substring(0, i).split(/[\r\n]/).length
var file = path.basename(filename, '.css')
return '_' + file.replace('.', '-') + '_' + line + '_' + name
},
}),
],
sourcemap: process.env.NODE_ENV !== 'production',
}
/** @type {import('esbuild').BuildOptions} */
const extensionConfig = {
...base,
entryPoints: ['./src/extension.ts'],
external: ['vscode'],
outdir: './out',
platform: 'node',
}
/** @type {import('esbuild').BuildOptions} */
const appConfig = {
...base,
entryPoints: ['./src/app/index.tsx'],
loader: {
'.ttf': 'dataurl',
},
minify: true,
outdir: './out/app',
platform: 'browser',
}
try {
if (process.argv.includes('--watch')) {
console.log('[watch] build started')
await (await context(extensionConfig)).watch()
await (await context(appConfig)).watch()
console.log('[watch] build finished')
} else {
await build(extensionConfig)
await build(appConfig)
}
} catch (error) {
if (error) {
error.errors?.forEach((error) =>
console.error(
`> ${error.location.file}:${error.location.line}:${error.location.column}: error: ${error.text}`
)
) || console.log(error)
}
process.stderr.write(error.stderr)
process.exit(1)
}