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
Core bundling functionality that orchestrates the entire build process for both client and server targets in Nuxt applications.
The primary export that handles the complete build process for Nuxt applications using Vite.
/**
* Main bundling function for Nuxt applications using Vite
* Configures and executes both client and server builds with optimized settings
* @param nuxt - Nuxt instance containing configuration and build context
*/
function bundle(nuxt: Nuxt): Promise<void>;Usage Example:
import type { Nuxt } from "@nuxt/schema";
import { bundle } from "@nuxt/vite-builder";
// Assuming you have a configured Nuxt instance
const nuxt: Nuxt = await loadNuxt({ for: 'build' });
// Execute the complete build process
await bundle(nuxt);
// This will:
// 1. Configure Vite settings for both client and server
// 2. Set up development servers (if in dev mode)
// 3. Configure all necessary plugins
// 4. Execute client build
// 5. Execute server build
// 6. Generate manifestsThe bundle function creates and manages the ViteBuildContext throughout the build process.
interface ViteBuildContext {
/** Nuxt application instance containing all configuration */
nuxt: Nuxt;
/** Merged Vite configuration for the build */
config: ViteConfig;
/** Resolved path to the application entry file */
entry: string;
/** Optional Vite development server for client-side assets */
clientServer?: ViteDevServer;
/** Optional Vite development server for SSR assets */
ssrServer?: ViteDevServer;
}The bundle function performs sophisticated configuration merging between Nuxt and Vite settings.
Key Configuration Areas:
Core Configuration Applied:
// Example of key configuration areas managed by bundle()
const viteConfig = {
resolve: {
alias: {
'#app': nuxt.options.appDir,
// Asset directory aliases
[basename(nuxt.options.dir.assets)]: resolve(nuxt.options.srcDir, nuxt.options.dir.assets),
// All user-defined aliases from nuxt.config
...nuxt.options.alias,
},
},
define: {
__NUXT_VERSION__: JSON.stringify(nuxt._version),
__NUXT_ASYNC_CONTEXT__: nuxt.options.experimental.asyncContext,
},
build: {
rollupOptions: {
output: {
sanitizeFileName: sanitizeFilePath,
assetFileNames: // Configures asset naming with hash patterns
},
},
},
plugins: [
// All Nuxt-specific Vite plugins
],
};The bundle function integrates with Nuxt's hook system for extensibility.
Key Hooks Called:
vite:extend - Allows modification of the build context before processingvite:extendConfig - Enables configuration modifications for both client and servervite:serverCreated - Called when development servers are createdvite:compiled - Triggered after successful compilationHook Usage Example:
// In a Nuxt module or plugin
nuxt.hook('vite:extendConfig', (config, { isClient, isServer }) => {
if (isClient) {
// Modify client-specific configuration
config.plugins.push(myClientPlugin());
}
if (isServer) {
// Modify server-specific configuration
config.plugins.push(myServerPlugin());
}
});The bundle function automatically adapts behavior based on nuxt.options.dev:
Development Mode:
Production Mode:
The bundle function includes comprehensive error handling and logging:
Install with Tessl CLI
npx tessl i tessl/npm-nuxt--vite-builder