Vite (oc-vite fork with external assets support)

raw JSON →
7.1.12 verified Mon Apr 27 auth: no javascript

oc-vite is a modified fork of Vite that enables external asset support in library mode. Current stable version is 7.1.12. It follows Vite's release cadence and provides all Vite 7 features plus custom asset handling for library builds. The key differentiator is allowing users to configure external assets (e.g., images, fonts) as separate files instead of inlining them, which is useful for library authors publishing to npm. It ships TypeScript declarations and requires Node ^20.19.0 or >=22.12.0. Compared to standard Vite, oc-vite adds a specific hook or configuration option for library assets; otherwise identical to Vite in API and behavior.

error Error: @vitejs/plugin-vue requires vue (>=3.2.13) or @vue/compiler-sfc to be present in the dependency tree.
cause Missing required peer dependency when using Vue plugin.
fix
npm install vue@^3.2.13 or yarn add vue@^3.2.13.
error Error: You installed esbuild on another platform than the one you're currently on. This won't work.
cause Incorrect esbuild binary for the current OS due to npm cache or wrong node version.
fix
Delete node_modules and package-lock.json, then run 'npm install' again. Alternatively, reinstall esbuild: 'npm rebuild esbuild'.
error Error: Cannot find module 'vite'
cause Vite not installed or not in node_modules.
fix
Run 'npm install vite' or 'yarn add vite'.
error Error: Could not resolve 'react/jsx-runtime' (added by Vite's pre-bundling)
cause Vite's pre-bundling fails to resolve certain React packages when using React 17/18 without the automatic JSX runtime.
fix
Ensure 'react/jsx-runtime' is installed (available in React 17+). Add to 'optimizeDeps.include' if needed.
breaking Vite 5 dropped CommonJS support entirely; require() will fail.
fix Switch to ESM imports (import { ... } from 'vite') or use dynamic import().
breaking Since Vite 4, the default Node.js resolver no longer handles .json or .wasm imports without explicit extensions.
fix Append file extensions e.g., import data from './data.json' with { assert: { type: 'json' } }.
gotcha Using the `define` config option with strings that contain template literals can break due to unsafe minification.
fix Wrap values in JSON.stringify() to avoid syntax errors, e.g., __APP_VERSION__: JSON.stringify('1.0.0').
deprecated The `optimizeDeps.force` option is deprecated and no longer functional since Vite 6.
fix Use `optimizeDeps.include` and `optimizeDeps.exclude` explicitly instead.
npm install oc-vite
yarn add oc-vite
pnpm add oc-vite

Demonstrates a basic Vite library configuration with external dependencies and multiple output formats.

import { defineConfig } from 'vite'
import { resolve } from 'path'

export default defineConfig({
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.ts'),
      name: 'MyLib',
      formats: ['es', 'cjs', 'umd'],
    },
    rollupOptions: {
      external: ['react'],
      output: {
        globals: {
          react: 'React',
        },
      },
    },
  },
})