when I run vite build aka npm run build the build performs without errors.
I see built in 4661ms. but the process never finishes. It just hangs.
How can I make the process end and exit?
You can easily exit Vite by hooking into the buildEnd and closeBundle events.
Define a plugin as follows:
// file vite-plugin-close.ts
export default function ClosePlugin() {
return {
name: 'ClosePlugin', // required, will show up in warnings and errors
// use this to catch errors when building
buildEnd(error) {
if(error) {
console.error('Error bundling')
console.error(error)
process.exit(1)
} else {
console.log('Build ended')
}
},
// use this to catch the end of a build without errors
closeBundle(id) {
console.log('Bundle closed')
process.exit(0)
},
}
}
Import the plugin in your vite.config.ts
// file vite.config.ts
import ClosePlugin from './vite-plugin-close.ts'
// ...
// place the plugin in the *vite* plugins section
// NOT the rollupOptions.plugins section
plugins: [ClosePlugin()],
The same thing applies for JS files, just switch the extensions.
✓ 3662 modules transformed.
dist/bundle/cli.js 8,825.66 kB
Bundle closed
(base) ➜ cli git:(main) ✗
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With