Vite bundler for Nuxt applications providing seamless integration between Nuxt's framework and Vite's build system
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Client-side build pipeline handling browser-optimized bundles, CSS processing, and development server setup for Nuxt applications.
Creates browser-optimized builds with development server integration for client-side assets.
/**
* Build client-side assets with Vite
* Handles browser-specific configuration, development server setup, and production optimization
* @param nuxt - Nuxt instance with client configuration
* @param ctx - Vite build context containing entry and config
*/
function buildClient(nuxt: Nuxt, ctx: ViteBuildContext): Promise<void>;Usage Example:
import { buildClient } from "@nuxt/vite-builder/client";
import type { ViteBuildContext } from "@nuxt/vite-builder";
// Called internally by bundle(), but can be used directly
const ctx: ViteBuildContext = {
nuxt,
config: viteConfig,
entry: './app/entry.client.ts'
};
await buildClient(nuxt, ctx);The buildClient function applies browser-specific Vite configuration.
Key Configuration Areas:
// Client-specific configuration applied
const clientConfig = {
define: {
'process.server': false,
'process.client': true,
'process.browser': true,
'import.meta.server': false,
'import.meta.client': true,
'import.meta.browser': true,
},
optimizeDeps: {
entries: [ctx.entry],
exclude: [
// Vue ecosystem packages excluded from optimization
'vue', '@vue/runtime-core', '@vue/runtime-dom',
'vue-router', 'nuxt', 'nuxt/app',
// Nuxt dependencies
'@unhead/vue', 'consola', 'defu', 'h3', 'ofetch'
]
},
build: {
sourcemap: nuxt.options.sourcemap.client,
manifest: 'manifest.json',
outDir: resolve(nuxt.options.buildDir, 'dist/client'),
rollupOptions: {
input: { entry: ctx.entry }
}
}
};In development mode, buildClient creates and configures a Vite development server.
/**
* Vite development server created for client builds
* Provides HMR, file watching, and middleware integration
*/
interface ViteDevServer {
/** Middleware stack for handling requests */
middlewares: Connect.Server;
/** Module graph for dependency tracking */
moduleGraph: ModuleGraph;
/** Close the development server */
close(): Promise<void>;
}Development Server Features:
Development Server Example:
// Development server is automatically created and configured
// Access via build context after buildClient() completes
if (nuxt.options.dev && ctx.clientServer) {
// Server is available for middleware integration
const viteMiddleware = defineEventHandler(async (event) => {
// Vite handles the request through its middleware stack
await new Promise((resolve, reject) => {
ctx.clientServer!.middlewares.handle(event.node.req, event.node.res, (err) => {
err ? reject(err) : resolve(null);
});
});
});
}In production mode, buildClient generates optimized static assets.
Production Features:
// Production build output structure
// .nuxt/dist/client/
// ├── manifest.json // Asset manifest
// ├── [hash].js // Entry chunks
// ├── assets/[hash].css // Extracted CSS
// └── assets/[hash].[ext] // Static assetsThe buildClient function registers several client-specific Vite plugins.
/**
* Development style SSR plugin for client builds
* @param options - Plugin configuration for style handling
* @returns Vite plugin instance
*/
function DevStyleSSRPlugin(options: {
srcDir: string;
buildAssetsURL: string;
}): Plugin;
/**
* Runtime paths plugin for asset URL resolution
* @returns Vite plugin instance
*/
function RuntimePathsPlugin(): Plugin;
/**
* Module preload polyfill for older browsers
* @returns Vite plugin instance
*/
function ModulePreloadPolyfillPlugin(): Plugin;
/**
* Stable entry plugin for consistent chunk hashing
* @param nuxt - Nuxt instance
* @returns Vite plugin instance
*/
function StableEntryPlugin(nuxt: Nuxt): Plugin;Client builds handle various asset types with specific processing.
Asset Types Processed:
Asset Configuration:
// Asset file naming patterns
const assetConfig = {
chunkFileNames: nuxt.options.dev ? undefined : '[hash].js',
entryFileNames: nuxt.options.dev ? 'entry.js' : '[hash].js',
assetFileNames: chunk =>
withoutLeadingSlash(join(nuxt.options.app.buildAssetsDir,
`${sanitizeFilePath(filename(chunk.names[0]!))}.[hash].[ext]`))
};Hot Module Replacement is configured for optimal development experience.
interface HMRConfig {
/** Protocol for HMR connection (ws/wss) */
protocol?: 'ws' | 'wss';
/** Port for HMR server */
port?: number;
/** Custom HMR server instance */
server?: Server;
}HMR Features:
Optional bundle analysis integration for production builds.
/**
* Analyze plugin for bundle visualization
* @param nuxt - Nuxt instance with analysis configuration
* @returns Promise resolving to array of Vite plugins
*/
function AnalyzePlugin(nuxt: Nuxt): Promise<Plugin[]>;Analysis Configuration:
// Enable in nuxt.config.ts
export default defineNuxtConfig({
build: {
analyze: true, // or { enabled: true, ... }
}
});Install with Tessl CLI
npx tessl i tessl/npm-nuxt--vite-builder