Use parcel for watching esbuild build files

Seeing small but consistent cpu usage when using esbuild's watcher. Switch to parcel to avoid this
This commit is contained in:
Matt Bierner
2022-03-23 14:48:54 -07:00
parent 5f5a917796
commit e7fffbf1c9
5 changed files with 142 additions and 86 deletions

View File

@@ -2,8 +2,10 @@
* 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 path = require('path');
const esbuild = require('esbuild');
const watcher = require('@parcel/watcher');
const args = process.argv.slice(2);
@@ -15,20 +17,29 @@ if (outputRootIndex >= 0) {
outputRoot = args[outputRootIndex + 1];
}
const srcDir = path.join(__dirname, 'preview-src');
const outDir = path.join(outputRoot, 'media');
esbuild.build({
entryPoints: [
path.join(__dirname, 'preview-src', 'index.ts'),
path.join(__dirname, 'preview-src', 'pre'),
],
bundle: true,
minify: true,
sourcemap: false,
format: 'esm',
outdir: outDir,
platform: 'browser',
target: ['es2020'],
watch: isWatch,
incremental: isWatch,
}).catch(() => process.exit(1));
function build() {
return esbuild.build({
entryPoints: [
path.join(srcDir, 'index.ts'),
path.join(srcDir, 'pre'),
],
bundle: true,
minify: true,
sourcemap: false,
format: 'esm',
outdir: outDir,
platform: 'browser',
target: ['es2020'],
});
}
build().catch(() => process.exit(1));
if (isWatch) {
watcher.subscribe(srcDir, () => {
return build();
});
}