fix: refactor esbuild setup to support watch (#6608)
This commit is contained in:
parent
2837345250
commit
c9ad4a6b78
1 changed files with 14 additions and 7 deletions
|
@ -81,15 +81,15 @@ export default async function build(...args) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const builder = await esbuild.build({
|
const rebuildPlugin = {
|
||||||
...config,
|
name: 'astro:rebuild',
|
||||||
watch: {
|
setup(build) {
|
||||||
onRebuild(error, result) {
|
build.onEnd(async result => {
|
||||||
if (prebuilds.length) {
|
if (prebuilds.length) {
|
||||||
prebuild(...prebuilds);
|
await prebuild(...prebuilds);
|
||||||
}
|
}
|
||||||
const date = dt.format(new Date());
|
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')));
|
console.error(dim(`[${date}] `) + red(error || result.errors.join('\n')));
|
||||||
} else {
|
} else {
|
||||||
if (result.warnings.length) {
|
if (result.warnings.length) {
|
||||||
|
@ -99,12 +99,17 @@ export default async function build(...args) {
|
||||||
}
|
}
|
||||||
console.log(dim(`[${date}] `) + green('✔ updated'));
|
console.log(dim(`[${date}] `) + green('✔ updated'));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
|
|
||||||
|
const builder = await esbuild.context({
|
||||||
|
...config,
|
||||||
entryPoints,
|
entryPoints,
|
||||||
outdir,
|
outdir,
|
||||||
format,
|
format,
|
||||||
plugins: [
|
plugins: [
|
||||||
|
rebuildPlugin,
|
||||||
svelte({ isDev }),
|
svelte({ isDev }),
|
||||||
...(copyWASM
|
...(copyWASM
|
||||||
? [
|
? [
|
||||||
|
@ -120,6 +125,8 @@ export default async function build(...args) {
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await builder.watch();
|
||||||
|
|
||||||
process.on('beforeExit', () => {
|
process.on('beforeExit', () => {
|
||||||
builder.stop && builder.stop();
|
builder.stop && builder.stop();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue