Skip to content

Commit

Permalink
fix: refactor esbuild setup to support watch (#6608)
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored Mar 20, 2023
1 parent 2837345 commit c9ad4a6
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions scripts/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ export default async function build(...args) {
return;
}

const builder = await esbuild.build({
...config,
watch: {
onRebuild(error, result) {
const rebuildPlugin = {
name: 'astro:rebuild',
setup(build) {
build.onEnd(async result => {
if (prebuilds.length) {
prebuild(...prebuilds);
await prebuild(...prebuilds);
}
const date = dt.format(new Date());
if (error || (result && result.errors.length)) {
if (result && result.errors.length) {
console.error(dim(`[${date}] `) + red(error || result.errors.join('\n')));
} else {
if (result.warnings.length) {
Expand All @@ -99,12 +99,17 @@ export default async function build(...args) {
}
console.log(dim(`[${date}] `) + green('✔ updated'));
}
},
});
},
};

const builder = await esbuild.context({
...config,
entryPoints,
outdir,
format,
plugins: [
rebuildPlugin,
svelte({ isDev }),
...(copyWASM
? [
Expand All @@ -120,6 +125,8 @@ export default async function build(...args) {
],
});

await builder.watch();

process.on('beforeExit', () => {
builder.stop && builder.stop();
});
Expand Down

0 comments on commit c9ad4a6

Please sign in to comment.