vite-plugin-sdk

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

Vite plugin to bundle SDKs with support for ESM and CJS outputs. Current stable version: 0.1.5. Active development with frequent releases. Extensible via defu. Only works with Vite 4, 5, 6, or 7. Provides TypeScript type declarations. Key differentiator: focused solely on SDK bundling, with automatic externalization based on package.json dependencies, built-in DTS generation, and support for internal dependencies. Lightweight alternative to full Rollup setups for SDK authors.

error Error: Plugin vite-plugin-sdk: `dts` option requires `typescript` as a peer dependency.
cause TypeScript is not installed when `dts: true`.
fix
Run npm install --save-dev typescript or set dts: false.
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/vite-plugin-sdk not supported.
cause Using CommonJS `require()` to import an ESM-only package.
fix
Switch to import sdk from 'vite-plugin-sdk' in an ESM-configured project.
error TypeError: Cannot read properties of undefined (reading 'dependencies')
cause `packageJSON` option not provided and plugin cannot find a package.json from CWD.
fix
Provide an explicit packageJSON option pointing to your package.json.
error vite build output is empty (no files generated)
cause `srcDir` does not point to a valid directory containing source files.
fix
Set srcDir correctly, e.g., srcDir: 'lib' if your entry is in lib/index.ts.
gotcha Package is ESM-only. Use `import` syntax; `require()` will throw.
fix Use `import sdk from 'vite-plugin-sdk'` in your Vite config. Ensure `"type": "module"` in package.json or use .mjs extension.
breaking Peer dependency Vite supports major versions 4, 5, 6, and 7. Using older Vite versions may break.
fix Update Vite to ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0.
deprecated Option `packageJSON` path resolution may be deprecated in favor of explicit path in future versions.
fix Always provide an explicit `packageJSON` option to avoid relying on CWD-based discovery.
gotcha If `dts: true`, TypeScript must be installed (peer dependency). Build will fail otherwise.
fix Install typescript >=5 as a devDependency.
gotcha Plugin automatically externalizes all dependencies listed in `dependencies` and `peerDependencies` of package.json. To bundle them, add to `internalDependencies`.
fix Use the `internalDependencies` array to explicitly include packages that should be bundled.
gotcha Source directory defaults to `src`. If your SDK code is elsewhere (e.g., `lib`), builds will produce empty output.
fix Set `srcDir` to the correct source directory relative to project root.
npm install vite-plugin-sdk
yarn add vite-plugin-sdk
pnpm add vite-plugin-sdk

Minimal Vite config using vite-plugin-sdk to bundle an SDK with type declarations.

// vite.config.ts
import { defineConfig } from 'vite';
import sdk from 'vite-plugin-sdk';

export default defineConfig({
  plugins: [
    sdk({
      dts: true,
      internalDependencies: [],
      srcDir: 'src',
    }),
  ],
});