useRuntimeDependencies #

Declares the packages that a plugin imports from its runtime code, so both module graphs resolve them from the plugin's own installation instead of from the site root.

Usage #

Parameters

configUserConfig

The Vite config that the vite() handler received.

ownerstring

The package that owns the dependencies, usually the plugin itself.

dependenciesreadonly string[]

Names of the packages the plugin imports from its runtime code.

Notes #

Sites usually install a preset or kawapress, not every package a plugin uses, so a nested dependency cannot be imported by name from the site root. The declaration therefore names the package that owns the dependency and the helper derives the packages that lead from the site to it. Vite's optimizer expects that path as an owner > dependency chain.

Call it from the vite() handler: the client dependency optimizer then pre-bundles these packages before the first request instead of discovering them after it and reloading the page, and the SSR build bundles them so Node never loads a second copy of Vue from node_modules.

TypeScript
import { useRuntimeDependencies } from 'kawapress/generator'

api.vite((config) => {
  useRuntimeDependencies(config, '@your-scope/plugin-name', ['some-browser-lib'])
})
Full type signature
TypeScript
function useRuntimeDependencies(config: UserConfig, owner: string, dependencies: readonly string[]): void

Edit this page

Comments