vite-plugin-no-bundle

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

Vite plugin that enables building libraries without bundling, preserving the module structure for monorepos and native ESM consumption. Current stable version is 4.0.0 (requires Vite 5). The plugin marks all modules as external, copies static assets like CSS as-is, and supports multiple output formats (ESM, CJS). Released relatively actively with breaking changes in major versions. Differentiators: allows deep imports, consumer-side bundling, and tailored code splitting.

error Error: The plugin 'vite-plugin-no-bundle' requires Vite version >=5.0.0. Current version: 4.x.x
cause Using plugin v4 with Vite 4.
fix
Upgrade to Vite 5 (npm install vite@latest) or downgrade plugin to v3.x.
error TypeError: noBundlePlugin is not a function
cause Importing plugin incorrectly using named import.
fix
Use default import: import noBundlePlugin from 'vite-plugin-no-bundle'
error Module not found: Can't resolve 'vite-plugin-no-bundle' in ...
cause Package not installed or CJS require() used with ESM-only package.
fix
Install package (npm i -D vite-plugin-no-bundle) and use ESM import.
breaking v4.0.0 drops Vite 4 support, requires Vite 5.
fix Upgrade to Vite 5 or stay on plugin v3.x if using Vite 4.
breaking v3.0.0 removes the 'fileNames' option in favor of 'build.lib.fileName'.
fix Use Vite's built-in 'build.lib.fileName' option instead.
deprecated The plugin is ESM-only. CommonJS require() will throw Module not found or similar errors.
fix Switch to ESM imports or use dynamic import().
gotcha When using non-ESM output formats (e.g., CJS), static asset imports will break because import.meta.url is ESM-only.
fix Use ESM format ('es') for library mode if static assets are needed.
gotcha The 'root' option must match your source folder (default 'src'). Misconfiguration leads to wrong relative paths in output.
fix Set 'root' to the directory containing your entry point (e.g., 'lib' or 'src').
npm install vite-plugin-no-bundle
yarn add vite-plugin-no-bundle
pnpm add vite-plugin-no-bundle

Configures Vite to build a library without bundling, preserving file structure and copying CSS assets.

import { defineConfig } from 'vite';
import noBundlePlugin from 'vite-plugin-no-bundle';

export default defineConfig({
  build: {
    lib: {
      formats: ['es'],
      entry: 'src/index.ts',
    },
  },
  plugins: [
    noBundlePlugin({
      copy: '**/*.css',
      internal: ['some/dependency'],
      root: 'src',
    }),
  ],
});