UNPKG

@octohash/vite-config

Version:

A personal ready-to-use Vite configuration repository, opinionated but customizable.

190 lines (189 loc) 6.24 kB
import * as vite0 from "vite"; import { AliasOptions, PluginOption, UserConfig } from "vite"; import { PluginVisualizerOptions } from "rollup-plugin-visualizer"; import { PluginOptions } from "vite-plugin-dts"; import { VitePluginFederationOptions } from "@originjs/vite-plugin-federation"; import { VitePluginVueDevToolsOptions } from "vite-plugin-vue-devtools"; import { PluginOptions as PluginOptions$1 } from "@intlify/unplugin-vue-i18n"; 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 { GeneratorOptions } from "@jspm/generator"; //#region src/plugins/app-loading/index.d.ts interface AppLoadingPluginOptions { rootContainer?: string; title?: string; filePath?: string; } //#endregion //#region src/plugins/import-map.d.ts interface ImportMapPluginOptions extends GeneratorOptions { downloadDeps?: boolean; debug?: boolean; defaultProvider?: 'jspm.io' | 'jsdelivr' | 'unpkg' | 'esm.sh'; include?: string[]; exclude?: string[]; } //#endregion //#region src/plugins/license.d.ts interface LicensePluginOptions { name?: string; author?: string; version?: string; description?: string; homepage?: string; license?: string; contact?: string; copyright?: { holder?: string; year?: string | number; }; } //#endregion //#region src/plugins/metadata.d.ts interface MetadataPluginOptions { extendMetadata?: Record<string, unknown>; } //#endregion //#region src/types.d.ts type ProjectType = 'app' | 'lib'; interface CommonPluginOptions { /** * https://github.com/btd/rollup-plugin-visualizer * By default template path is: ./node_modules/.cache/visualizer/stats.html * * @default false */ visualizer?: boolean | PluginVisualizerOptions; /** * 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?: UserConfig; } interface ConditionPlugin { condition?: boolean; plugins: () => PluginOption[] | PromiseLike<PluginOption[]>; } type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>; //#endregion //#region src/index.d.ts declare function defineConfig(options: OptionsConfig): vite0.UserConfigFnPromise; //#endregion export { AppPluginOptions, CommonPluginOptions, ConditionPlugin, LibPluginOptions, OptionsConfig, OptionsVue, ProjectType, ResolvedOptions, defineConfig };