-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
82 lines (74 loc) · 2.38 KB
/
esbuild.config.mjs
File metadata and controls
82 lines (74 loc) · 2.38 KB
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
import * as esbuild from 'esbuild';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const production = process.argv.includes('--production');
const watch = process.argv.includes('--watch');
const targetArg = process.argv.find((arg) => arg === 'extension' || arg === 'plugin');
const scriptDir = dirname(fileURLToPath(import.meta.url));
/** @type {esbuild.Plugin} */
const esbuildProblemMatcherPlugin = {
name: 'esbuild-problem-matcher',
setup(build) {
build.onStart(() => {
if (watch) console.log('[watch] build started');
});
build.onEnd((result) => {
for (const { text, location } of result.errors) {
console.error(`✘ [ERROR] ${text}`);
if (location) {
console.error(` ${location.file}:${location.line}:${location.column}:`);
}
}
if (watch) console.log('[watch] build finished');
});
},
};
/** @type {esbuild.BuildOptions} */
const shared = {
bundle: true,
platform: 'node',
format: 'cjs',
minify: production,
sourcemap: production ? false : true,
sourcesContent: false,
external: ['vscode'],
alias: {
'@react-pug/react-pug-core': resolve(scriptDir, 'packages/react-pug-core/src/index.ts'),
},
define: {
'process.env.NODE_ENV': JSON.stringify(production ? 'production' : 'development'),
},
logLevel: watch ? 'info' : 'warning',
plugins: [esbuildProblemMatcherPlugin],
};
const allConfigs = {
extension: {
...shared,
entryPoints: [resolve(scriptDir, 'packages/vscode-react-pug-tsx/src/index.ts')],
outfile: resolve(scriptDir, 'packages/vscode-react-pug-tsx/dist/client.js'),
},
plugin: {
...shared,
entryPoints: [resolve(scriptDir, 'packages/typescript-plugin-react-pug/src/index.ts')],
outfile: resolve(scriptDir, 'packages/typescript-plugin-react-pug/dist/plugin.js'),
},
};
const configs = targetArg
? [allConfigs[targetArg]]
: [allConfigs.extension, allConfigs.plugin];
async function main() {
if (watch && production) {
throw new Error('Cannot use --watch and --production together');
}
if (watch) {
const contexts = await Promise.all(configs.map(c => esbuild.context(c)));
await Promise.all(contexts.map(c => c.watch()));
console.log('Watching for changes...');
} else {
await Promise.all(configs.map(c => esbuild.build(c)));
}
}
main().catch((e) => {
console.error(e);
process.exit(1);
});