import { Plugin } from 'vite'; import { default as dts } from 'vite-plugin-dts'; import { PackageJson } from './packageJson.ts'; /** * Vite preset for all our support packages: * - externalizes all non-dev-dependencies * - generates type declarations (using `vite-plugin-dts`) */ export declare function vitePresetPlugin({ dtsOptions, externalize, bundleIn, isApplication, }?: DependencyManagementOptions & { /** Additional options for `vite-plugin-dts` */ dtsOptions?: Parameters[0] | false; }): [Plugin, Plugin, Promise | undefined]; /** * Options for externalizing dependencies. */ export type DependencyManagementOptions = { /** * Force bundle in these dependencies even if they are declared as * dependencies or peerDependencies. * * @example * This is desirable if you wish to control the version of a dependency or * need to post-process the dependency in some way. Usually, you will declare * such as a devDependency, but there is a use case for declaring it as a * dependency instead: * * - If TypeScript types from the bundled in dependencies are referenced in * the `.d.ts` files of your library, you will need to declare the package * as a `dependency`, so that it is still installed on the consumer's * computer so that TypeScript can correctly resolve the types of that * library. */ readonly bundleIn?: (RegExp | string)[]; /** * Force externalize these dependencies, even if they are declared as * devDependencies. * * @example * This is desirable if you are sure the end user will have these dependencies * available, yet do not wish to declare these as devDependencies for some * technical reasons. */ readonly externalize?: (RegExp | string)[]; /** * By default, this plugin errors if any devDependency is used in runtime code * to avoid bundling in dependencies in a library. In application packages, * bundling in everything is desirable, so enable this option. * * @default false */ readonly isApplication?: boolean; }; /** * By default, Rollup will bundle-in all dependencies. * * We change it as follows: * Externalize all packages that are defined as * "dependency" or "peerDependency" in the package.json. * If you wish to bundle-in some package, define it as a "devDependency". * * Bundling-in packages is not recommended because: * - it makes our build take longer * - it pushes larger packages to NPM * - user of our library is locked into the version of the package we bundled in * - if user has two packages using the same library, there will be two copies * served on the page * - It may break some libraries/prevent them from optimizing correctly * depending on the production/development mode, or prevent them from loading * correct code depending on browser/node.js environment. * * For example, see this statement from Lit: * https://lit.dev/docs/ssr/authoring/#:~:text=Don%27t%20bundle%20Lit,based%20on%20environment. * * @see {@link ./buildCdn.ts} for CDN dependency bundling details * * @remarks * If a dependency is both a peerDependency and a devDependency, it will still * be externalized (because all peerDependencies are externalized). */ export declare function externalizeDependencies(options: DependencyManagementOptions): Plugin; interface PluginShape extends Plugin { resolveId: { filter: { id: { include: RegExp[]; exclude: RegExp[] | undefined; }; }; handler: (id: string, importer: string | undefined, options: { isEntry: boolean; }) => false | undefined; }; } declare function externalizeDependenciesImplementation(options: DependencyManagementOptions, packageJson: PackageJson): PluginShape; declare function matchesAny(id: string, patterns: readonly RegExp[]): boolean; export declare const exportsForTests: { stringToStartsWithGlob: (option: RegExp | string) => RegExp; externalizeDependenciesImplementation: typeof externalizeDependenciesImplementation; matchesAny: typeof matchesAny; }; export {};