-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugins' onEnd callback isn't triggerred in serve mode #1384
Comments
Thanks for the report. I have confirmed that this bug exists. However, the reason for this is due to how the JS API is implemented by calling the Go API, and fixing this isn't that straightforward. So it may not be fixed immediately. Some notes for me: JS |
Are there plans to solve this or get around it? Relying on |
@adamchipperfield Did you mean a file watcher? Serve mode is different from build({ watch: true }). The former does not watch file, instead it rebuilds the file everytime when a request to it comes in. You can rely on a real file watcher like chokidar or other and use plugins to refresh the watched file list. One may also use build-watch to implement the watcher if don't care the overhead of building twice. (and, that's what I got!: https://github.com/hyrious/esbuild-repl/blob/63cc74842a9343b945d51fca28dfe42a012d6171/scripts/dev.ts) |
For posterity, you can serve and build from the same script: let server;
if (serve) {
/** @type {esbuild.ServeOptions} */
const serveOptions = {
port: 5500,
servedir: './',
onRequest(args) {
const localPath = path.join(serveOptions.servedir, args.path);
if (localPath === buildOptions.outfile) {
console.log('accessed outfile');
}
},
};
server = await esbuild.serve(serveOptions, { entryPoints: [] });
console.log('esbuild server is listening on port', serveOptions.port);
}
await Promise.all([
server?.wait,
esbuild.build(buildOptions),
]); Just supply an empty buildOptions to For those using command line arguments instead of JS-based cli, this might help: const cliArgs = new Set(process.argv.slice(2));
const isProduction = (process.env.NODE_ENV === 'production') || cliArgs.has('--production');
const minifyAll = cliArgs.has('--minify');
const minifyWhitespace = cliArgs.has('--minify-whitespace');
const minifyIdentifiers = cliArgs.has('--minify-identifiers');
const minifySyntax = cliArgs.has('--minify-syntax');
const watch = cliArgs.has('--watch');
const serve = cliArgs.has('--serve'); |
I have
in
build
and everything works as expected. Bothbuild started
andbuild end
are printed properly.However,if I use
serve
withI got
hosted on http://0.0.0.0:8000
and multiplebuild started
only. I am suspecting the onEnd callback isn't called properly called in serve mode?The text was updated successfully, but these errors were encountered: