@octohash/vite-config
Version:
Opinionated Vite config preset.
196 lines (188 loc) • 6.41 kB
text/typescript
import * as vite from 'vite';
import { AliasOptions, UserConfig, PluginOption } from 'vite';
import { PluginOptions as PluginOptions$1 } from '@intlify/unplugin-vue-i18n';
import { VitePluginFederationOptions } from '@originjs/vite-plugin-federation';
import { Options } from 'unplugin-auto-import/types';
import { Options as Options$1 } from 'unplugin-vue-components';
import { Options as Options$2 } from 'unplugin-vue-router';
import { PluginOptions } from 'vite-plugin-dts';
import { VitePluginVueDevToolsOptions } from 'vite-plugin-vue-devtools';
import { GeneratorOptions } from '@jspm/generator';
interface AppLoadingPluginOptions {
container?: string;
title?: string;
filepath?: string;
}
interface ImportMapPluginOptions extends GeneratorOptions {
downloadDeps?: boolean;
debug?: boolean;
defaultProvider?: 'jspm.io' | 'jsdelivr' | 'unpkg' | 'esm.sh';
include?: string[];
exclude?: string[];
}
interface LicensePluginOptions {
name?: string;
author?: string;
version?: string;
description?: string;
homepage?: string;
license?: string;
contact?: string;
copyright?: {
holder?: string;
year?: string | number;
};
}
interface MetadataPluginOptions {
extendMetadata?: Record<string, unknown>;
}
type ProjectType = 'app' | 'lib';
interface CommonPluginOptions {
/**
* https://github.com/KusStar/vite-bundle-visualizer
* By default template path is: ./node_modules/.cache/visualizer/stats.html
*
* @default false
*/
visualizer?: boolean | {
help?: boolean;
template?: 'treemap' | 'sunburst' | 'network';
output?: string;
open?: boolean;
config?: string;
};
/**
* Inject license info to output files
* Load license file from `package.json`, if it is a monorepo project, the root `package.json` will also be merged
*
* @default true
*/
license?: boolean | LicensePluginOptions;
/**
* https://github.com/originjs/vite-plugin-federation
* Module federation
*/
federation?: VitePluginFederationOptions;
}
interface AppPluginOptions {
/**
* https://github.com/chenxch/vite-plugin-dynamic-base
* If you want to build once and deploy to multiple environments, you can enable this plugin to set publicPath at runtime
* You can set like this: `dynamicBase: 'window.__dynamic_base__'`
*/
dynamicBase?: string;
/**
* Inject app loading to `index.html`
* You can customize the root element and loading template
* Use `[app-loading-title]` as a placeholder to dynamically set the document title during loading`
*
* @default auto-detect based on `projectType === 'app'`
*/
appLoading?: boolean | AppLoadingPluginOptions;
/**
* Injects metadata using `define`, accessible via `__VITE_APP_METADATA__`.
* Includes information such as author, build time, version, and more.
*
* @default auto-detect based on `projectType === 'app'`
*/
metadata?: boolean | MetadataPluginOptions;
/**
* Generates an import map for the project.
* Based on https://github.com/jspm/vite-plugin-jspm, with extended CDN provider support and options for include/exclude.
*
* @default false
*/
importMap?: boolean | ImportMapPluginOptions;
}
interface LibPluginOptions {
/**
* https://github.com/qmhc/vite-plugin-dts
* Generates declaration files from .ts or .vue source files
*
* @default auto-detect based on `projectType === 'lib'`
*/
dts?: boolean | PluginOptions;
}
interface OptionsVue {
/**
* https://github.com/vuejs/devtools
* Enable Vue Devtools
*
* @default false
*/
devtools?: boolean | VitePluginVueDevToolsOptions;
/**
* https://github.com/intlify/bundle-tools
* Enable Vue I18n
*
* @default false
*/
i18n?: boolean | PluginOptions$1;
/**
* https://github.com/unplugin/unplugin-auto-import
* Auto-imports commonly used APIs such as `vue`, `vue-router`, `pinia`, `@vueuse/core`, etc
* Also supports auto-importing UI components from libraries like `ant-design-vue`, `element-plus`, etc
* Files from `src/composables` and `src/utils` will also be auto-imported.
*
* @default auto-detect based on `projectType === 'app'`
*/
imports?: boolean | Options;
/**
* https://github.com/unplugin/unplugin-vue-components
* Enabled by default when the project type is `app`
* The `directoryAsNamespace` option is enabled by default.
*
* @default auto-detect based on `projectType === 'app'`
*/
components?: boolean | Options$1;
/**
* https://github.com/posva/unplugin-vue-router
* Enabled by default when the project type is `app`
* Folder(s) to scan for files and generate routes. Defaults to scanning the pages directory.
*
* @default auto-detect based on `projectType === 'app'`
*/
pages?: boolean | Options$2;
}
interface OptionsConfig extends CommonPluginOptions, AppPluginOptions, LibPluginOptions {
/**
* Whether to build for production
*
* @default auto-detect based on `command === 'build'`
*/
isBuild?: boolean;
/**
* Type of the project
*
* @default auto-detect based on the `index.html` file
*/
type?: ProjectType;
/**
* Aliases used to replace values in `import` or `require` statements
* Paths are automatically resolved if needed
*
* @default { "@": "./src" }
*/
alias?: AliasOptions;
/**
* Enable Vue support
* The goal is to provide an automatic registration mechanism similar to Nuxt in app development.
*
* @default auto-detect based on the dependencies
*/
vue?: boolean | OptionsVue;
/**
* Vite configuration override
*
* @default {}
*/
vite?: UserConfig;
}
interface ConditionPlugin {
condition?: boolean;
plugins: () => PluginOption[] | PromiseLike<PluginOption[]>;
}
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
declare function defineConfig(options: OptionsConfig): vite.UserConfigFnPromise;
export { defineConfig };
export type { AppPluginOptions, CommonPluginOptions, ConditionPlugin, LibPluginOptions, OptionsConfig, OptionsVue, ProjectType, ResolvedOptions };