-
Notifications
You must be signed in to change notification settings - Fork 127
/
build.js
110 lines (99 loc) · 2.14 KB
/
build.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const { context, build } = require('esbuild');
const { dependencies, devDependencies } = require('./package.json');
const { tailwindPlugin } = require('esbuild-plugin-tailwindcss');
/**
* @type {import('esbuild').BuildOptions}
*/
const sharedConfig = {
entryPoints: ['./src/index.ts'],
bundle: true,
minify: true,
// sourcemap: true,
external: [
'fs',
'path',
'child_process',
'os',
'vm',
'stream',
'node:fs/promises',
'url',
// === from package.json
...Object.keys(dependencies),
...Object.keys(devDependencies),
],
};
/**
* @type {import('esbuild').BuildOptions}
*/
const cjsConfig = {
...sharedConfig,
platform: 'node', // For CJS
outfile: './out/cjs/index.cjs',
target: 'node16',
};
/**
* @type {import('esbuild').BuildOptions}
*/
const esmConfig = {
...sharedConfig,
// TODO: Support browser
platform: 'neutral', // For ESM
outfile: './out/esm/index.mjs',
};
/**
* @type {import('esbuild').BuildOptions}
*/
const webviewConfig = {
entryPoints: ['./src/webview/preview.tsx', './src/webview/backlinks.tsx'],
bundle: true,
minify: true,
platform: 'browser',
// outfile: './out/webview/index.js',
outdir: './out/webview',
loader: {
'.png': 'dataurl',
'.woff': 'dataurl',
'.woff2': 'dataurl',
'.eot': 'dataurl',
'.ttf': 'dataurl',
'.svg': 'dataurl',
},
plugins: [tailwindPlugin({})],
};
async function main() {
try {
if (process.argv.includes('--watch')) {
// CommonJS
const cjsContext = await context({
...cjsConfig,
sourcemap: true,
});
// ESM
const esmContext = await context({
...esmConfig,
sourcemap: true,
});
// Webview
const webviewContext = await context({
...webviewConfig,
sourcemap: true,
});
await Promise.all([
cjsContext.watch(),
esmContext.watch(),
webviewContext.watch(),
]);
} else {
// CommonJS
await build(cjsConfig);
// ESM
await build(esmConfig);
// Webview
await build(webviewConfig);
}
} catch (error) {
console.error(error);
}
}
main();