UNPKG

@plugin-light/project-config-uni-vite

Version:

开箱即用的项目配置,适用于 uni-app Vue3.x 项目

201 lines (200 loc) 6.05 kB
/// <reference types="node" /> import type { BuildOptions, CommonServerOptions, Plugin, ServerOptions } from 'vite'; import tailwindcss from 'tailwindcss'; import type { Options as RemoveSelectorOptions } from '@plugin-light/postcss-plugin-remove-selector'; import type { Options as TransformWebTagOptions } from '@plugin-light/postcss-plugin-transform-web-tag'; import type { ICrossGameStyleOptions } from '@plugin-light/vite-plugin-cross-game-style'; import type { IRemoveVueDirectionOptions } from '@plugin-light/vite-plugin-remove-vue-directive'; import type { UniTailwindPluginUserOptions } from '@uni-helper/vite-plugin-uni-tailwind'; import type { Options as LegacyOptions } from '@vitejs/plugin-legacy'; import type { Server } from 'node:https'; import type { Options as ESBuildOptions } from 'rollup-plugin-esbuild'; /** * `vite-plugin-mkcert` 参数(仅列出常用字段,透传给 mkcert 插件) */ export interface IMkcertOptions { /** * mkcert 二进制下载源 * * - `github`: 官方源(境外访问快) * - `coding`: 腾讯 CODING 镜像源(内网友好,**推荐**) * * @default 'coding' */ source?: 'github' | 'coding'; /** * 是否自动升级 mkcert 二进制 * @default false */ autoUpgrade?: boolean; /** * 需要签发证书的 host 列表,默认覆盖 localhost / 127.0.0.1 / ::1 及本机 IP */ hosts?: string[]; /** * 是否强制重新生成证书 * @default false */ force?: boolean; /** * 本地已有的 mkcert 二进制绝对路径,指定后不再下载 */ mkcertPath?: string; /** * 下载 mkcert 二进制时使用的代理,例如 `http://127.0.0.1:7890` */ proxy?: string; /** * 证书文件(key / cert)保存路径 */ savePath?: string; /** * 私钥文件名 */ keyFileName?: string; /** * 证书文件名 */ certFileName?: string; } export interface IUniViteConfigOptions { /** * 模式 */ mode: string; /** * uni 插件 */ uni: any; /** * 端口,传递给 `server.port` * * ⚠️ 注意:`uni-app` 项目下这个参数**不会生效**,端口由 `manifest.json` 的 * `h5.devServer.port` 决定(`@dcloudio/uni-h5-vite` 会用 manifest 覆盖)。 * * @default 443 */ port?: CommonServerOptions['port']; /** * https 配置,传递给 `server.https` * * ⚠️ 同 `port`,`uni-app` 项目下由 `manifest.json` 的 `h5.devServer.https` 决定。 */ https?: Server; /** * host 配置,传递给 `server.host` * @default true */ host?: CommonServerOptions['host']; /** * 是否启用 `vite-plugin-mkcert`,为本地 dev server 生成受系统信任的 HTTPS 证书。 * * 推荐场景: * - 用 `whistle` 等代理中转 HTTPS 请求到本地 dev server 时,需要"系统级信任"的 * 证书才能稳定完成 TLS 握手,否则会出现 `socket hang up` 等错误 * - 需要抓包 / 复用生产域名的本地调试场景 * * 传 `true` 时使用默认参数 `{ source: 'coding' }`;传对象则透传给 `vite-plugin-mkcert`。 * * 仅在 H5(`isH5=true`)下生效,小程序场景下会被忽略。 * * @default true */ useMkcert?: boolean | IMkcertOptions; /** * 前置插件 */ prePlugins?: Array<Plugin>; /** * 后置插件 */ postPlugins?: Array<Plugin>; /** * 对应 optimizeDeps.include */ optimizeDepsIncludes?: Array<string>; /** * remove-vue-direction 插件参数 */ removeVueDirectionOptions?: IRemoveVueDirectionOptions; /** * hmr 选项 * @default { timeout: 1000 * 60 * 5 } */ hmr?: ServerOptions['hmr']; /** * 语法警报列表,比如 v-model,destroyed */ warnList?: ICrossGameStyleOptions['warnList']; /** * transform-web-tag postcss 插件参数 */ transformWebTagOptions?: boolean | TransformWebTagOptions; /** * remove selector postcss 插件参数 */ removeSelectorOptions?: boolean | RemoveSelectorOptions; /** * uniTailwind 插件参数 */ uniTailwindOptions?: boolean | UniTailwindPluginUserOptions; /** * tailwindcss postcss 插件参数 */ tailwindcssOptions?: boolean | Parameters<typeof tailwindcss>[0]; /** * 构建选项 */ buildOptions?: BuildOptions; /** * 是否使用 chunk-split * @default false */ useChunkSplit?: boolean; /** * 是否使用 @vitejs/plugin-legacy,传递对象格式将作为插件参数 * @default false */ useLegacy?: boolean | LegacyOptions; /** * 传递给 uni 插件的参数 */ uniOptions?: any; /** * 是否使用 rollup-plugin-esbuild,传递对象格式将作为插件参数 */ useESBuildPlugin?: boolean | ESBuildOptions; /** * 是否使用 pmd-network-v2 * @default false */ usePMDNetworkV2?: boolean; /** * 是否使用文件轮询监听(usePolling) * * 轮询比原生 fs.watch 慢且 CPU 占用高,仅在 Docker/WSL 等不支持 inotify 的环境下需要开启 * @default true */ usePolling?: boolean; /** * 是否开启 visualizer 产物分析插件 * * 设为 false 可跳过 gzip/brotli 计算,加快构建速度 * @default true */ useVisualizer?: boolean; /** * 是否使用 @rollup/plugin-node-resolve * * Vite 内部已有 resolve 能力,关闭可减少重复解析开销 * @default true */ useNodeResolve?: boolean; /** * 构建目标,传递给 build.target(仅 H5 生效) * * 如果不需要兼容旧浏览器,可设为 'es2020' 或 'esnext' 以减少 polyfill,加快构建 * @default 'es2015' */ buildTarget?: string; }