/* eslint-disable no-unused-vars */ import type { Options } from 'ts-import-plugin'; import type { RuleSetRule, WebpackPluginInstance, Configuration, CleanPlugin } from 'webpack'; import type { ProxyArray, ProxyConfigArray, ProxyConfigMap } from 'webpack-dev-server'; import type { Request, Response, NextFunction } from 'express'; import type { JsMinifyOptions } from '@swc/core'; import type { MinifyOptions } from 'terser'; import { Options as AssetHtmlOptions } from 'add-asset-html-webpack-plugin'; import { Options as HtmlWebpackPluginOptions } from 'html-webpack-plugin'; export interface RequestFormData extends Request { files: Buffer[]; } export type ProxyFuncType = (req: RequestFormData, res: Response, next: NextFunction) => void; // eslint-disable-next-line @typescript-eslint/no-explicit-any export type MockConfiguration = Record | null>; export type MinifierType = 'swc' | 'terser'; export declare type AppType = 'mobile' | 'site' | 'back-stage' | 'single-spa' | 'library'; export type TerserOptions = MinifyOptions; export type SwcOptions = JsMinifyOptions; export declare type ConfigType = { clean: boolean | CleanPlugin['options']; /** 渲染模式 */ mode: 'ssr' | 'csr'; /** 编译器 */ compiler: 'tsc' | 'swc'; /** swc 配置项,仅当编译器为 swc 时有效 */ // eslint-disable-next-line @typescript-eslint/no-explicit-any swcrc?: Record | ((isDev: boolean) => Record); /** * 自定义entry * 当你需要添加一些polyfill函数时可在这里添加 * 比如兼容es10的object.fromentries: * @example * ``` * const config = { * entry: { * polyfillObjectFromentries: 'polyfill-object.fromentries' * } * } * ``` **/ entry?: Record; /** 压缩配置 */ minifier: { type?: MinifierType; options?: SwcOptions | TerserOptions; css?: 'cssnano' | 'parcelCss'; }; /** 环境变量, 可通过 process.env 获取 */ // eslint-disable-next-line @typescript-eslint/no-explicit-any env?: Record; /** mini-idc 数据持久化配置, 为 false 时关闭持久化 */ miniIdc?: | { /** 持久化数据使用的key, 当key为 'none' 时, 关闭持久化 */ programName?: string; /** 持久化数据是否加密 */ encrypt?: boolean; /** 自定义RSA加密密钥 */ encryptKey?: string; } | false; devtool?: Configuration['devtool']; sourceMap?: SourceMapDevToolPluginOptions | false; /** 路径别名映射 */ alias?: { [key: string]: string; }; /** 根路由 */ routeBaseName: string; /** 输出目录前置路径,默认: / */ publicPath: string; /** 设计图尺寸 默认: 1680 */ designSize: number; /** 自定义降级组件 */ fallbackCompPath?: string | null; /** less 全局变量 */ modifyVars: Record; /** antd 主题配置 */ antdThemeVariables: { compact?: boolean; dark?: boolean; }; /** 类名前缀 */ prefixCls?: string; /** 左侧菜单栏, 不需要时设置为 false, 仅 type: back-stage 时有效 */ layoutSider: | false | { theme?: 'light' | 'dark'; breakpoint?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'; }; /** 自定义 webpack module rules */ moduleRules: RuleSetRule[]; /** node_modules中, 需要开启 cssModules 的模块 */ cssModules: string[]; /** 按需引入 */ importOnDemand: T extends 'tsc' ? Partial[] : Record; /** 开发服务器代理 */ proxy: ProxyArray | ProxyConfigArray | ProxyConfigMap; /** 自定义缓存目录,为 false 时,不使用缓存 */ cacheDirectory: string | false; /** 开发服务器设置 */ devServer: { allowedHosts?: string[]; host?: string; port?: number; https?: boolean; compress?: boolean; }; /** HtmlWebpackPlugin Option */ htmlPluginOption: HtmlWebpackPluginOptions & { tags?: { textContent?: string; tag?: string; [key: string]: string | null | boolean | number; }[]; }; /** 自定义插入 html 的 js 和 css */ assetHtml: AssetHtmlOptions[]; /** 路由模式 默认 browser */ routerMode: 'hash' | 'browser' | 'memory'; /** webpack 插件 */ plugins: WebpackPluginInstance[]; /** 对生产chunk进行拆分 */ splitChunk?: false | OptimizationSplitChunksOptions; runtimeChunk?: | boolean | 'single' | 'multiple' | { // eslint-disable-next-line @typescript-eslint/ban-types name?: string | Function; }; /** dll化的模块 */ dll: Record; /** dll所在文件夹 */ dllDirectory: string; /** 通过Web字体加载加载的字体 */ webFontLoader: string[]; /** 编译输出路径 */ output: string; /** 模块联邦 */ moduleFederation: ModuleFederationOption[]; /** 跳过编译的模块 */ externals?: Configuration['externals']; rulesInclude?: { less?: string[]; css?: string[]; js?: string[]; media?: string[]; fonts?: string[]; }; }; export declare interface ModuleFederationOption { /** 模块名称,唯一性,不能重名 */ name: string; /** 打包的模块文件名 默认: remote_entry.js */ filename?: string; library?: { type: 'var' | string; name: string; }; runtime?: string; /** 表示作为 Host 时, 去消费哪些 Remote */ remotes?: { /** 远程模块名称 */ name: string; /** 远程模块文件名 默认: remote_entry.js */ filename?: string; /** 远程模块访问地址 */ host: string; /** 远程模块别名 * @example * ```javascript * const remote = { * name: 'a-b-c', * // 设置别名为ABC * alias: 'ABC', * library: ['react'], * } * // 通过别名导入 * import React from 'ABC/react'; * ``` */ alias?: string; /** 从此模块加载的library * @example * ```javascript * const library = ['react', 'lodash']; * // 所有通过react、lodash的导入将被转换成 * import ... from '远程模块名/react'; * import ... from '远程模块名/lodash'; * ``` */ library?: string[]; }[]; /** 当前模块具体导出去的内容 * @example * ```javascript * const exposes = [ * // 导出 node_modules下 的 react * "react", * // 导出 node_modules下 的 lodash * "lodash", * // 导出自定义组件 * { * // 给这个组件取名为Button * name: 'Button', * // 组件的源码位置 * path: './src/btn/index.tsx', * } * ] * // 其它项目接入后使用Button组件 * import Button from '模块名/Button'; * import React from '模块名/react'; * ``` */ exposes?: ( | string | { /** 组件名称 */ name: string; /** 组件源码路径 */ path: string; } )[]; /** 优先用 Host 的依赖, 如果 Host 没有, 再用自己的 */ shared?: Record | string[]; } export declare interface SharedConfig { /** *直接在异步请求后面包含提供的和后备模块。这也允许在初始加载中使用此共享模块。所有可能的共享模块也都需要急切。 */ eager?: boolean; /** *应提供共享范围的提供的模块。如果在共享作用域中找不到共享模块或版本无效,则还充当回退模块。默认为属性名称。 */ import?: number; /** *软件包名称,用于从描述文件中确定所需的版本。仅当无法根据请求自动确定包名称时才需要。 */ packageName?: string; /** *共享范围中来自模块的版本要求。 */ requiredVersion?: number; /** *在共享范围内的此键下查找模块。 */ shareKey?: string; /** *共享范围名称。 */ shareScope?: string; /** *在共享范围内仅允许共享模块的单个版本(默认情况下处于禁用状态)。 */ singleton?: boolean; /** *如果版本无效,则不接受共享模块(默认为是,如果本地后备模块可用并且共享模块不是单例,否则为no,如果未指定所需的版本,则无效)。 */ strictVersion?: boolean; /** *所提供模块的版本。将替换较低的匹配版本,但不会替换较高的版本。 */ version?: number; } export declare type CommomType = { PROGRAMPATH: string; NODE_ENV?: string; APPTYPE: AppType; ENTRYPATH: { [K in AppType]: string; }; DEV: boolean; CONFIG: ConfigType; DLL: string[]; log: (msg: string) => void; }; export declare interface SourceMapDevToolPluginOptions { append?: null | string | false; columns?: boolean; exclude?: string | RegExp | Rule[]; fallbackModuleFilenameTemplate?: string | typeof Function; fileContext?: string; filename?: null | string | false; include?: string | RegExp | Rule[]; module?: boolean; moduleFilenameTemplate?: string | typeof Function; namespace?: string; noSources?: boolean; publicPath?: string; sourceRoot?: string; test?: string | RegExp | Rule[]; } export type ProgramInfoType = { /** 应用名称 */ name: string; /** 应用描述 */ description: string; /** 应用版本 */ version: string; /** 应用类型 */ type: 'mobile' | 'site' | 'back-stage' | 'single-spa' | 'library'; /** 开发者 */ author: | { name: string; email?: string; } | string; /** 存储库 */ repository: string; /** 路由模式 */ routerMode: 'hash' | 'browser' | 'memory'; /** 根路由 */ routeBaseName: string; /** 设计尺寸 */ designSize: number; /** 渲染模式 */ renderMode: 'ssr' | 'csr'; }; export type CoverageType = { /** 语句(statement coverage) */ statements: string; /** 语句覆盖: 是不是每个语句都执行了 */ coveredstatements: string; /** 条件(branch coverage) */ conditionals: string; /** 条件覆盖: 是不是每个条件代码块都执行了 */ coveredconditionals: string; /** 函数(function coverage) */ methods: string; /** 函数覆盖: 是不是每个函数都调用了 */ coveredmethods: string; }; export type ProjectCoverageType = { /** 元素 */ elements: string; /** 覆盖元素 */ coveredelements: string; complexity: string; loc: string; ncloc: string; /** 经过测试的组件 */ packages: string; /** 经过测试的文件 */ files: string; /** 经过测试的类 */ classes: string; }; declare interface OptimizationSplitChunksOptions { /** * Sets the name delimiter for created chunks. */ automaticNameDelimiter?: string; /** * Assign modules to a cache group (modules from different cache groups are tried to keep in separate chunks, default categories: 'default', 'defaultVendors'). */ cacheGroups?: { // eslint-disable-next-line @typescript-eslint/ban-types [index: string]: string | false | Function | RegExp | OptimizationSplitChunksCacheGroup; }; /** * Select chunks for determining shared modules (defaults to "async", "initial" and "all" requires adding these chunks to the HTML). */ chunks?: 'all' | 'initial' | 'async' | ((chunk: Chunk) => boolean); /** * Sets the size types which are used when a number is used for sizes. */ defaultSizeTypes?: string[]; /** * Size threshold at which splitting is enforced and other restrictions (minRemainingSize, maxAsyncRequests, maxInitialRequests) are ignored. */ enforceSizeThreshold?: number | { [index: string]: number }; /** * Options for modules not selected by any other cache group. */ fallbackCacheGroup?: { /** * Sets the name delimiter for created chunks. */ automaticNameDelimiter?: string; /** * Select chunks for determining shared modules (defaults to "async", "initial" and "all" requires adding these chunks to the HTML). */ chunks?: 'all' | 'initial' | 'async' | ((chunk: Chunk) => boolean); /** * Maximal size hint for the on-demand chunks. */ maxAsyncSize?: number | { [index: string]: number }; /** * Maximal size hint for the initial chunks. */ maxInitialSize?: number | { [index: string]: number }; /** * Maximal size hint for the created chunks. */ maxSize?: number | { [index: string]: number }; /** * Minimal size for the created chunk. */ minSize?: number | { [index: string]: number }; /** * Minimum size reduction due to the created chunk. */ minSizeReduction?: number | { [index: string]: number }; }; /** * Sets the template for the filename for created chunks. */ filename?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string); /** * Prevents exposing path info when creating names for parts splitted by maxSize. */ hidePathInfo?: boolean; /** * Maximum number of requests which are accepted for on-demand loading. */ maxAsyncRequests?: number; /** * Maximal size hint for the on-demand chunks. */ maxAsyncSize?: number | { [index: string]: number }; /** * Maximum number of initial chunks which are accepted for an entry point. */ maxInitialRequests?: number; /** * Maximal size hint for the initial chunks. */ maxInitialSize?: number | { [index: string]: number }; /** * Maximal size hint for the created chunks. */ maxSize?: number | { [index: string]: number }; /** * Minimum number of times a module has to be duplicated until it's considered for splitting. */ minChunks?: number; /** * Minimal size for the chunks the stay after moving the modules to a new chunk. */ minRemainingSize?: number | { [index: string]: number }; /** * Minimal size for the created chunks. */ minSize?: number | { [index: string]: number }; /** * Minimum size reduction due to the created chunk. */ minSizeReduction?: number | { [index: string]: number }; /** * Give chunks created a name (chunks with equal name are merged). */ // eslint-disable-next-line @typescript-eslint/ban-types name?: string | false | Function; /** * Compare used exports when checking common modules. Modules will only be put in the same chunk when exports are equal. */ usedExports?: boolean; } export interface SwcImportOnDemandTransformCtx { source: string; name: string; } export type SwcImportOnDemandTransformFn = ( ctx: SwcImportOnDemandTransformCtx ) => string | string[] | undefined | null | false; export type SwcImportOnDemandTransform = string | string[] | SwcImportOnDemandTransformFn; export interface SwcImportOnDemandConfig { transform: SwcImportOnDemandTransform; style?: boolean | string; } declare global { // eslint-disable-next-line vars-on-top,no-var var NEKOCLICONFIG: CommomType; } export {};