vite-plugin-rebundle
v2.0.7
Published
Vite plugin that forces single-file output per entry. Ensures each entry point is bundled into a standalone file without code-splitting.
Readme
vite-plugin-rebundle
A Vite plugin that guarantees one standalone file per entry point. It rebundles each entry into a single file with no shared chunks or dynamic imports. Requires Vite 8+.
Why?
Vite does not provide single-file output for multi-entry builds. When code splitting is needed, each entry can produce extra chunks and dynamic imports.
vite-plugin-rebundle solves that by taking Vite's build output and rebundling each entry with rolldown. It runs only during vite build and does not affect the dev server.
Installation
npm install -D vite-plugin-rebundleUsage
Add the plugin to your Vite config:
import { defineConfig } from 'vite'
import { rebundle } from 'vite-plugin-rebundle'
export default defineConfig({
plugins: [rebundle()],
build: {
rolldownOptions: {
input: {
bundle1: 'src/bundle1.js',
bundle2: 'src/bundle2.js',
},
output: {
entryFileNames: '[name].js',
},
},
},
})Configuration
rebundle() accepts up to two arguments:
- The first argument contains global
rolldowninput and output options applied to every entry. - The second argument contains per-entry options that are deep-merged with the global ones.
export default defineConfig({
plugins: [
rebundle(
// Global options applied to all bundles
{
input: {...},
output: {...},
},
// Per-entry options, will be deep-merged with global options
{
bundle1: {
input: {...},
output: {...},
},
bundle2: {
input: {...},
output: {...},
},
},
),
],
build: {
rolldownOptions: {
input: {
bundle1: 'src/bundle1.js',
bundle2: 'src/bundle2.js',
},
output: {
entryFileNames: '[name].js',
},
},
},
})How it works
When you run vite build, vite-plugin-rebundle:
- Lets Vite perform the normal build.
- Rebundles each entry with rolldown.
- Writes back a single self-contained JavaScript file per entry.
Watch Mode
When running in build watch mode, the plugin exposes import.meta.env.REBUNDLE_PORT. You can use it to listen for rebundle events over WebSocket:
const ws = new WebSocket(`ws://localhost:${import.meta.env.REBUNDLE_PORT}`)
ws.addEventListener('message', e => console.log('Rebundle event:', e.data))Notes
Source maps are not currently supported. If you pass sourcemap option, it will be ignored.
