Replies: 1 comment
|
Keep the returned bundles and dispose them when your Nuxt hook decides the watched shape has changed: import { build } from 'tsdown'
let bundles: Awaited<ReturnType<typeof build>> | undefined
async function startTsdown() {
bundles = await build({
entry: ['src/index.ts'],
outDir: 'dist',
watch: true,
})
}
async function stopTsdown() {
await Promise.all(bundles?.map((b) => b[Symbol.asyncDispose]()) ?? [])
bundles = undefined
}If your entry is a glob, tsdown already has restart logic for created/deleted entry files. For Nuxt-specific files outside tsdown's build graph, close the current bundles with Source/docs: https://tsdown.dev/advanced/programmatic-usage and |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I am developing a Nuxt module that uses tsdown programmatically to bundle some files into a package that is then usable in the Nuxt app.
I would like to watch the files for changes, and potentially terminate the tsdown build, in case new files are added, or certain key files are removed. There is the "watch: true" option to watch, and there is the Nuxt "builder:watch" hook to alert my module for affected files being added/removed... But how can I terminate the build() call?
The closest thing to that I have managed to do is to use incremental builds, but that still means my "builder:watch" hook needs to re-evaluate if the changed files are files that should cause a rebuild, which feels like it would be less efficient on larger projects. My hope is to rely on tsdown's watch for changes, since it already knows all of the files involved, which would keep the "builder:watch" hook faster.
On a related note, using incremental builds causes the source files to have the ".js" and ".d.ts" outputted next to them, even though the source files are outside of the "outDir" (though still within the "root")... I'm not sure if that's a bug or intended behavior, but either way, that makes incremental not exactly ideal either.
All reactions