Registry / web-framework / vite-plugin-builder

vite-plugin-builder

JSON →
library1.0.0jsnpmunverified

A Vite plugin that simplifies dual compilation for SSR (Server-Side Rendering) and CSR (Client-Side Rendering) in a single Vite project. Version 1.0.0 supports Vite ^4||^5||^6. It allows building both server and client entry points simultaneously, streamlining workflows for modern SPAs requiring SSR. Notably, it provides separate output directories for server (dist/) and client (dist/public/) assets, with configurable server build options and external dependencies. Written in TypeScript, it offers type safety and minimal setup compared to manual dual-build configurations.

npm install vite-plugin-builder
INSTALL
IMPORT
SIG · VITE-PLUGIN-BUILDE
V
vite-plugin-builder
web-frameworkjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

builder
import builder from 'vite-plugin-builder'
import { builder } from 'vite-plugin-builder'
Default export; named import will fail.
BuilderOptions
import type { BuilderOptions } from 'vite-plugin-builder'
import { BuilderOptions } from 'vite-plugin-builder'
TypeScript type exported; import as type to avoid runtime issues. Use 'import type' for type-only imports.
ViteConfig
import type { ViteConfig } from 'vite-plugin-builder'
import { ViteConfig } from 'vite-plugin-builder'
TypeScript type for server build config override function. Not a class or value.

Configures Vite with the builder plugin: sets server entry, client entry, and custom build defines for SSR/CSR dual compilation.

// vite.config.ts import { defineConfig } from 'vite'; import path from 'path'; import react from '@vitejs/plugin-react-swc'; import builder from 'vite-plugin-builder'; export default defineConfig({ base: '/', plugins: [ react(), builder({ serverEntry: 'server/main.js', clientEntry: { main: 'index.html', }, serverConfig: { define: { 'BUILD.BASE': '"/"', 'BUILD.BASE_API': '"/api"', 'BUILD.STATIC_DIR': '"public"', 'BUILD.SERVER_IP': '"0.0.0.0"', 'BUILD.SERVER_PORT': '3001', }, }, }), ], });
Debug
Known issues
gotchaBuilder plugin overrides Vite's output directory structure; server output goes to dist/, client to dist/public/. Do not manually set 'outDir' in Vite config as it will conflict with plugin's internal logic.
fix
Do not set 'outDir' in your Vite config; allow the plugin to manage output directories automatically.
affects: >=1.0.0
gotchaclientEntry expects an object mapping logical names to HTML template files. Using a plain string will cause a build error.
fix
Use { main: 'index.html' } instead of just 'index.html'.
affects: >=1.0.0
gotchaThe plugin automatically externalizes dependencies when serverConfig.external is set to 'true'. If you need specific externals, provide an array instead.
fix
Set external: ['express', 'react'] for fine-grained control, or avoid setting it to keep default behavior.
affects: >=1.0.0
gotchaserverBuild function receives a Vite config object and must return it; omitting the return statement will break the build.
fix
Always return the modified viteConfig object from serverBuild.
affects: >=1.0.0
breakingVersion 1.0.0 drops support for Vite 3; only Vite ^4, ^5, ^6 are supported.
fix
Upgrade Vite to version 4 or later.
affects: >=1.0.0
Errors
Common errors & fixes
Error: The plugin 'vite-plugin-builder' doesn't support Vite version 3.x. Please upgrade to Vite 4 or later.
Using Vite 3 which is not supported by the plugin.
fix
Upgrade Vite to version >=4: npm install vite@latest
TypeError: builder is not a function
Named import instead of default import.
fix
Change import statement to: import builder from 'vite-plugin-builder'
Error: Cannot find module 'vite-plugin-builder'
Package not installed or import path incorrect.
fix
Run npm install vite-plugin-builder --save-dev or yarn add vite-plugin-builder --dev, and ensure import path is correct.
Error: Expected options.clientEntry to be an object, got string
Passed a string to clientEntry instead of an object.
fix
Wrap value in an object: clientEntry: { main: 'index.html' }
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
viterequiredPeer dependency; plugin requires Vite version ^4, ^5, or ^6 to function.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
vite-plugin-builder — npm install vite-plugin-builder · libregistry