
Vite
Configure Vite library mode, multi-page builds, and SSR development patterns when shipping a Nuxt or Vite-based frontend or publishable JS package.
Overview
vite is an agent skill for the Build phase that documents Vite library mode, multi-page rolldown input, and SSR-oriented configuration for Nuxt projects.
Install
npx skills add https://github.com/onmax/nuxt-skills --skill viteWhat is this skill?
- Library mode with single or multiple entry points and es/umd or es/cjs output formats
- Rolldown externals and globals for Vue/React peer dependencies
- package.json exports map for import, require, and CSS side effects
- Multi-page app rolldown input from multiple HTML entry files
- SSR-oriented build and dev configuration snippets from the Nuxt skills pack
Adoption & trust: 1.5k installs on skills.sh; 674 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need to publish a Vite-built library or run multi-entry SSR without guessing exports, externals, and output format rules.
Who is it for?
Indie devs shipping component libraries, Nuxt modules, or multi-HTML Vite apps who want canonical config blocks in one place.
Skip if: Teams that only tweak unrelated README copy or backend-only services with no Vite frontend pipeline.
When should I use this skill?
Configuring Vite library builds, package exports, multi-page inputs, or SSR-related Vite settings in a Nuxt or Vite repo.
What do I get? / Deliverables
After applying the skill, your agent produces a vite.config.ts and package.json pairing that matches Vite’s library and MPA conventions.
- Updated vite.config.ts with lib or MPA build block
- package.json exports aligned to dist output
Recommended Skills
Journey fit
Build-phase frontend tooling: authors production vite.config.ts patterns before the app ships. Library exports, rolldown externals, and HTML entry maps are core frontend build setup, not runtime API work.
How it compares
Reference snippets for vite.config.ts—not a replacement for Nuxt’s full module authoring guide or an MCP deploy server.
Common Questions / FAQ
Who is vite for?
Solo and small-team builders using Vite or Nuxt who need library mode, package exports, or multi-page build entries spelled out as working TypeScript examples.
When should I use vite?
Use it in the Build phase when configuring distributable libraries, peer dependency externals, or multiple HTML inputs before you run production builds or publish to npm.
Is vite safe to install?
Treat it as documentation-only procedural knowledge; review the Security Audits panel on this Prism page before installing from the skills.sh registry.
SKILL.md
READMESKILL.md - Vite
# Build and SSR ## Library Mode Build a library for distribution: ```ts // vite.config.ts import { resolve } from 'node:path' import { defineConfig } from 'vite' export default defineConfig({ build: { lib: { entry: resolve(import.meta.dirname, 'lib/main.ts'), name: 'MyLib', fileName: 'my-lib', }, rolldownOptions: { external: ['vue', 'react'], output: { globals: { vue: 'Vue', react: 'React', }, }, }, }, }) ``` ### Multiple Entries ```ts build: { lib: { entry: { 'my-lib': resolve(import.meta.dirname, 'lib/main.ts'), secondary: resolve(import.meta.dirname, 'lib/secondary.ts'), }, name: 'MyLib', }, } ``` ### Output Formats - Single entry: `es` and `umd` - Multiple entries: `es` and `cjs` ### Package.json Setup ```json { "name": "my-lib", "type": "module", "files": ["dist"], "main": "./dist/my-lib.umd.cjs", "module": "./dist/my-lib.js", "exports": { ".": { "import": "./dist/my-lib.js", "require": "./dist/my-lib.umd.cjs" }, "./style.css": "./dist/my-lib.css" } } ``` ## Multi-Page App ```ts export default defineConfig({ build: { rolldownOptions: { input: { main: resolve(import.meta.dirname, 'index.html'), nested: resolve(import.meta.dirname, 'nested/index.html'), }, }, }, }) ``` ## SSR Development ### Middleware Mode Use Vite as middleware in a custom server: ```ts import express from 'express' import { createServer as createViteServer } from 'vite' const app = express() const vite = await createViteServer({ server: { middlewareMode: true }, appType: 'custom', }) app.use(vite.middlewares) app.use('*all', async (req, res, next) => { const url = req.originalUrl // 1. Read and transform index.html let template = await fs.readFile('index.html', 'utf-8') template = await vite.transformIndexHtml(url, template) // 2. Load server entry const { render } = await vite.ssrLoadModule('/src/entry-server.ts') // 3. Render app const appHtml = await render(url) // 4. Inject into template const html = template.replace('<!--ssr-outlet-->', appHtml) res.status(200).set({ 'Content-Type': 'text/html' }).end(html) }) app.listen(5173) ``` ### SSR Build ```json { "scripts": { "build:client": "vite build --outDir dist/client", "build:server": "vite build --outDir dist/server --ssr src/entry-server.ts" } } ``` The `--ssr` flag: - Externalizes dependencies by default - Outputs for Node.js consumption ### SSR Manifest Generate asset mapping for preload hints: ```bash vite build --outDir dist/client --ssrManifest ``` Creates `dist/client/.vite/ssr-manifest.json` mapping module IDs to chunks. ### SSR Externals Control which deps get bundled vs externalized: ```ts export default defineConfig({ ssr: { noExternal: ['some-package'], // Bundle this dep external: ['another-package'], // Externalize this dep }, }) ``` ### Conditional Logic ```ts if (import.meta.env.SSR) { // Server-only code (tree-shaken from client) } ``` ## JavaScript API ### createServer ```ts import { createServer } from 'vite' const server = await createServer({ configFile: false, root: import.meta.dirname, server: { port: 1337 }, }) await server.listen() server.printUrls() ``` ### build ```ts import { build } from 'vite' await build({ root: './project', build: { outDir: 'dist' }, }) ``` ### preview ```ts import { preview } from 'vite' const previewServer = await preview({ preview: { port: 8080, open: true }, }) previewServer.printUrls() ``` ### resolveConfig ```ts import { resolveConfig } from 'vite' const config = await resolveConfig({}, 'build') ``` ### loadEnv ```ts import { loadEnv } from 'vite' const env = loadEnv('development', process.cwd(), '') // Loads all env vars (empty prefix = no filtering)