import type { MdxOptions } from '@moneko/mdx'; import type { Config as SwcConfig, JsMinifyOptions as SwcMinifyOptions, ReactCompilerOptions } from '@swc/core'; import type { PluginOptions as MiniCssExtractPluginOptions } from 'mini-css-extract-plugin'; import type { MinifyOptions as TerserMinifyOptions } from 'terser'; import type { Configuration, ExternalsPresets, FileCacheOptions, MemoryCacheOptions, ModuleOptions, ResolvePluginInstance, RuleSetRule, WebpackPluginInstance, SourceMapDevToolPlugin, RuleSetConditionAbsolute, experiments, container, } from 'webpack'; import type { CopyPluginOption } from '../lib/plugin/copy.mjs'; import type { DonePluginOption } from '../lib/plugin/done.mjs'; import type { ManifestPluginOption } from '../lib/plugin/manifest/index.mjs'; import type { BundleAnalyzerOption } from './bundle-analyzer.d.ts'; import type { ESLintOption } from '../lib/plugin/eslint.mjs'; import type { StylelintOption } from '../lib/plugin/stylelint.mjs'; import type { SwcImportOnDemandTransform } from '../lib/commom/transfer-import-on-demand.mjs'; import type { CssInJsMinifyOption } from '../lib/commom/css-in-js-minify.mjs'; import type { CompressionPluginOptions } from '../lib/plugin/compression.mjs'; import type { JsxDomExpressions } from '../lib/options/jsx-dom-expressions.mjs'; import type { ProxyConfig } from '../lib/dev/proxy.mjs'; import type { OverrideResolverOption } from '../lib/plugin/override-resolve.mjs'; import type { OptimizationSplitChunksOptions } from '../lib/options/split-chunk.mjs'; import type { HtmlPluginOption } from '../lib/plugin/html-plugin.mjs'; export interface VirtualModulePluginOption { [key: string]: string | object; } export type { MiniCssExtractPluginOptions, SwcMinifyOptions, TerserMinifyOptions }; export type MinifierType = 'swc' | 'terser'; export declare type AppType = 'mobile' | 'site' | 'backstage' | 'micro' | 'library'; export declare type Framework = 'react' | 'solid'; export type RulesInclude = { css?: RuleSetConditionAbsolute[]; js?: RuleSetConditionAbsolute[]; media?: RuleSetConditionAbsolute[]; font?: RuleSetConditionAbsolute[]; wasm?: RuleSetConditionAbsolute[]; }; export interface Theme { primaryColor?: string; infoColor?: string; successColor?: string; processingColor?: string; errorColor?: string; warningColor?: string; } export type Experiments = Required['experiments']; export type LazyCompilationOptions = Experiments['lazyCompilation']; interface CacheConfig extends FileCacheOptions, MemoryCacheOptions { type?: 'filesystem' | 'memory'; } /** 进度条配置 */ interface BarOption { /** 进度条名称 */ name?: string; /** 进度条颜色 */ barColor?: string; /** 进度条名称颜色 */ nameColor?: string; /** 进度条背景颜色 */ barBgColor?: string; /** 进度消息颜色 */ msgColor?: string; /** 不展示进度条图形, 直接输出信息; 在 CI 中时默认为 `true`;*/ quiet?: boolean; } export declare type ConfigType = { /** react jsx 运行时 * @default 'automatic' */ reactJsxRuntime?: 'automatic' | 'classic' | 'preserve'; /** 是否启用 corepack * @default true */ corepack?: boolean; /** 启用严格模式 */ strict?: boolean; /** 软件包名称 */ bundleId?: string; bundles?: ('apk -release' | 'apk -debug' | 'ios -release' | 'ios -debug')[]; /** * @default true */ refresh?: boolean; /** 启用 polyfill; 当设置为 `true` 时, 则根据 `browserslist` 设置自动polyfill * @default false */ polyfill?: boolean; mode?: Configuration['mode']; /** swc 配置项,仅当编译器为 swc 时有效 */ swcrc?: SwcConfig | ((isDev: boolean) => SwcConfig); /** * 自定义entry * 当你需要添加一些polyfill函数时可在这里添加 * 比如兼容es10的object.fromentries: * @example * ``` * const config = { * entry: { * polyfillObjectFromentries: 'polyfill-object.fromentries' * } * } * ``` **/ entry?: Configuration['entry'] & { main?: string[] }; /** 压缩配置 */ minifier: SwcMinifyOptions | false; /** 环境变量, 可通过 process.env 获取 */ // eslint-disable-next-line @typescript-eslint/no-explicit-any env: Record; /** * @description 建议 * 开发模式: 'cheap-module-source-map' * 生产模式: 'eval-cheap-module-source-map' */ devtool?: Configuration['devtool']; /** * SourceMap 配置项 * @description 用于配置 SourceMapDevToolPlugin 的配置项, 当设置为 `false` 时, 不生成源码映射, 通常和 devtool 二选一 */ sourceMap?: SourceMapDevToolPluginOptions | false; /** 路径别名映射 */ alias: { [key: string]: string; }; /** 根路由 */ basename: string; /** 输出目录前置路径 * @default / * */ publicPath: string; rem?: { /** 设计图尺寸, 用于计算rem * @default 1920 * */ designSize: number; } | null; /** 自定义降级组件 */ fallbackCompPath?: string | null; /** less 全局变量 */ modifyVars: Record; /** 类名前缀 * @default n */ prefixCls?: string; /** 主题设置 */ theme?: Theme; /** 自定义 webpack module rules */ moduleRules: RuleSetRule[]; /** 解析js/ts前置的loader * @example * ```js * const conf: Partial = { * prefixJsLoader: [ * { * loader: 'babel-loader', * options: { * presets: ['solid'], * }, * }, * ], * }; * ``` * */ prefixJsLoader: RuleSetRule['use'][]; /** node_modules中, 需要开启 cssModules 的模块 * @description 用于指定哪些 node_modules 中的模块需要启用 CSS Modules 功能 */ cssModules: string[]; /** 为 cssModule 生成准确的声明文件 * @default true */ cssModuleDefinition: boolean; /** 按需引入 */ importOnDemand?: SwcImportOnDemandTransform; /** 开发服务器代理 * @example * ```js * const conf: Partial = { * proxy: [ * // /api/user/admin -> http://1.2.3.4:8008/user/admin * '/api/': { * target: 'http://1.2.3.4:8008/', * pathRewrite: { '^/api/': '/' }, * }, * // /bbs/2 -> http://1.2.3.4:9002/bbs/2 * '/bbs/': { * target: 'http://1.2.3.4:9002/', * }, * ], * }; * ``` */ proxy?: ProxyConfig; /** * 缓存配置 */ cache?: CacheConfig | false; /** 开发服务器设置 */ devServer: { headers?: Record; host?: string; port?: number; /** * 使用 HTTPS 服务器作为开发服务器 * @description * 如果你是macOS用户, 当启用 https 时, 第一次启动需要通过 `sudo ...` 启动提权以便安装证书; * ```bash * sudo npm start * ``` * @description * 配置 HTTPS 开发服务器的密钥和证书路径。 * * `key` 和 `cert` 参数指定了私钥和证书文件的位置。 * 请确保文件路径正确,并且文件存在于指定位置。 * * 如果私钥或证书加载失败,请检查以下事项: * 1. 文件路径是否正确。 * 2. 文件是否存在并具有正确的权限。 * 3. 文件内容是否有效。 * * @example * import type { ConfigType } from '@moneko/core'; * const conf: Partial = { * devServer: { * https: { * key: 'config/server.key', * cert: 'config/server.cert', * }, * }, * }; * export default conf; */ https?: | boolean | { /** 私钥文件的位置 * @example * // 表示加载当前项目 config 目录下的 server.key * 'config/server.key' * // 表示加载当前项目根目录下的 server.key * 'server.key' */ key: string; /** 证书文件的位置 * @example * // 表示加载当前项目 config 目录下的 server.cert * 'config/server.cert' * // 表示加载当前项目根目录下的 server.cert * 'server.key' */ cert: string; } | { /** 安装 CA 根证书 * @default true */ install: boolean; }; /** 打开浏览器 * @default true */ open?: boolean; }; /** HtmlPlugin Option */ htmlPluginOption: HtmlPluginOption | false; /** 需要拷贝的文件列表 * @example * ```ts * const conf = { * copy: { * // 将 public 下的 a.json 和 s.txt 添加到资源 * files: ['public/a.json', 'public/s.txt'], * // 将 static 文件夹添加到资源 * dirs: ['static'] * } * }; * * export default conf; * ``` */ copy: CopyPluginOption; /** 路由模式 * @description * 当在不支持 browserRouter 的环境(GitHub pages)使用 browserRouter, * 则需要添加设置 fixBrowserRouter * @default 'browser' * */ routerMode: 'hash' | 'browser' | 'memory'; /** 在不支持 browserRouter 的环境(GitHub pages)使用 browserRouter */ fixBrowserRouter?: | false | { /** 在不支持 browserRouter 的环境(GitHub pages)使用 browserRouter * @default 1 */ pathSegmentsToKeep: number; /** 文件输出路径 */ path?: string; }; /** webpack 插件 */ plugins: WebpackPluginInstance[]; /** resolve 插件 */ resolvePlugins: ResolvePluginInstance[]; /** 覆盖解析插件配置, 当设置为 `{}` 时为启用 * @default false * @example * import { resolveProgram } from '@moneko/core'; * * // 此时当 src 和 src-test 目录下有相同相对路径的文件时, * // 将优先使用 src-test 下的文件进行解析 * const conf = { * overrideResolve: { * original: resolveProgram('src'), // 这里可以省略, 默认为 src 目录, 当为组件库时, 默认为 site 目录 * override: resolveProgram('src-test'), * } * } */ overrideResolve: OverrideResolverOption | false; /** 对生产chunk进行拆分 * @description 用于配置生产环境下的代码分割策略。设置为 false 时禁用代码分割, * 或者可以传入一个配置对象来自定义分割行为,如分割点、chunk大小、缓存组等 */ splitChunk?: false | OptimizationSplitChunksOptions; /** 拆分 runtime 代码 * @description 运行时代码的分离方式。设置为 true 或 'multiple' 时会为每个入口创建一个运行时文件, * 设置为 'single' 时会创建一个所有入口共享的运行时文件。也可以通过对象形式自定义运行时文件的命名规则。 * @default 'single' */ runtimeChunk?: | boolean | 'single' | 'multiple' | { name?: string | ((entrypoint: { name: string }) => string); }; /** 编译输出路径 * @description 用于配置输出选项,可以是一个字符串(表示输出目录路径)或一个对象(包含详细的输出配置) */ output?: Omit | string; /** 模块联邦 * @description 用于配置模块联邦功能,实现跨应用间的代码共享和运行时依赖加载 * @example * // 导出模块示例 * { * name: 'demo_mf_name', * library: { type: 'var', name: 'demo_mf_name' }, * exposes: { * // 导出 react 和 react-dom * 'react', * 'react-dom', * // 导出 react-router * 'react-router', * // 导出 Button 组件 * './Button': './src/components/Button' * } * } * * // 引入远程模块示例 * { * name: 'demo_client_name', * remotes: [ * { * name: 'demo_mf_name', * host: 'http://localhost:3001/remoteEntry.js', * // 引用远程模块的依赖 * library: ['react', 'react-dom', 'react-router'], * } * ] * } */ moduleFederation: ModuleFederationOption[]; /** 跳过编译的模块 * @description 用于配置不需要被打包的外部依赖模块,这些模块将从打包过程中排除,并在运行时从外部获取 * @example * // 将 jQuery 设置为外部依赖 * externals: { * jquery: 'jQuery' * } * * // 使用数组形式排除多个模块 * externals: ['jquery', 'lodash'] * * // 使用正则表达式匹配要排除的模块 * externals: /^(jquery|\$)$/i */ externals?: Configuration['externals']; /** 规则包含配置 * @description 用于配置各类资源文件的编译包含规则 * @example * { * css: ['@sss/abc-ui', 'abc-comp'], // 编译这些模块下的 CSS 文件 * js: ['@sss/abc-ui', 'abc-comp'], // 只编译这些模块下的 JS/TS 文件 * media: ['@sss/abc-ui', 'abc-comp'], // 只编译这些模块下的媒体文件 * font: ['@sss/abc-ui', 'abc-comp'], // 只编译这些模块下的字体文件 * wasm: ['@sss/abc-ui', 'abc-comp'] // 只编译这些模块下的 WebAssembly 文件 * } */ rulesInclude?: RulesInclude; /** bundle分析 * @default false * @example * // 推荐 * { * analyzerMode: 'static', * reportFilename: 'report.html', * openAnalyzer: false, * } */ bundleAnalyzer: BundleAnalyzerOption | false; /** seo优化 * @default false */ seo: | { /** 域名 */ domain: string; /** 添加 .nojekyll 文件 * @description 告诉网站部署平台当前网站不是基于 Jekyll 构建的, * 不要忽略掉下划线开头的文件和文件夹 * @default false **/ jekyll?: boolean; /** 文件输出路径 */ path?: string; } | false; /** 📦 打包完成 */ done?: DonePluginOption; /** MDX 配置选项 * @description 用于配置 MDX 文件的解析和处理 */ mdx?: Omit; /** JSX DOM 表达式配置 * @description 用于配置 SolidJS JSX 语法中 DOM 表达式的处理方式 */ jsxDomExpressions?: JsxDomExpressions; /** 进度条配置 */ bar?: BarOption | false; /** 虚拟模块 * @example * const conf = { * virtualModule: { * 'custom-module-1': 'export default { name: "user1" };' * 'custom-module-2': { age: 12 } * } * } * // 使用 * import a from 'custom-module-1'; * import { age } from 'custom-module-2'; * console.log(a); // { name: "user1" } * console.log(age); // 12 */ virtualModule?: VirtualModulePluginOption; /** 是否使用 normalize css * @default true */ normalizeCss?: boolean; /** 外部依赖预设配置 * @description 用于配置哪些模块不需要被打包,而是在运行时从外部获取这些依赖 */ externalsPresets?: ExternalsPresets; /** 允许构建以http(s):协议开头的远程资源 */ buildHttp?: HttpUriOptions | (string | RegExp | ((uri: string) => boolean))[]; /** MiniCssExtractPlugin 配置项 */ cssExtract?: MiniCssExtractPluginOptions; /** 不进行编译不进行模块化分析 */ noParse?: ModuleOptions['noParse']; /** 懒编译 * @default false */ lazyCompilation?: LazyCompilationOptions; /** * 展示性能提示 * @description 资源(asset)和入口起点超过指定文件限制 */ performance?: Configuration['performance']; /** * 启用 React Compiler * @description 需要 react 17+ * @default false */ reactCompiler?: false | ReactCompilerOptions; /** stylelint 配置 * @description 为 false 时关闭 */ stylelint?: false | Partial; /** eslint 配置 * @description 为 false 时关闭 */ eslint?: false | Partial; /** 生成 DTS 文件的方式 * @default 'tsc' */ dts?: 'tsc' | 'swc'; cssInJs?: { /** * 压缩 css 模版字符串 */ minify?: CssInJsMinifyOption | false; }; /** * 最小 Chunk 尺寸 * @default 1000 * @description `1000` 打包体积大,速度快; * @description `512000` 打包体积小,速度更慢; */ minChunkSize?: number; /** * 是否进行压缩 */ compression?: boolean | Partial; recordsPath?: string; manifest?: false | Partial; }; /** * 用于构建 http 资源的选项 */ declare interface HttpUriOptions { /** 允许的 URI 列表 */ allowedUris: (string | RegExp | ((uri: string) => boolean))[]; /** * 存储锁定文件条目的资源内容的位置。 * 也可以通过传递 false 来禁用存储。 */ cacheLocation?: string | false; /** * 冻结; 设置后, 任何会导致锁定文件或任何资源内容修改的行为都将导致错误。 */ frozen?: boolean; /** * 锁定文件的位置 */ lockfileLocation?: string; /** * 代理配置,可用于指定用于 HTTP 请求的代理服务器 */ proxy?: string; /** * 升级, 设置后,将获取现有锁定文件条目的资源,并在资源内容更改时升级条目。 */ upgrade?: boolean; } type ModuleFederationPluginOption = ConstructorParameters[number]; type RequiredModuleFederationPluginOption = Required; type LibraryOption = RequiredModuleFederationPluginOption['library']; interface LibraryOptions extends LibraryOption { type: 'var' | 'module' | 'assign' | 'assign-properties' | 'this' | 'window' | 'self' | 'global' | 'commonjs' | 'commonjs2' | 'commonjs-module' | 'commonjs-static' | 'amd' | 'amd-require' | 'umd' | 'umd2' | 'jsonp' | 'system'; } export declare interface ModuleFederationOption extends Omit { /** 模块名称,唯一性,不能重名 */ name: string; /** 打包的模块文件名 默认: remote_entry.js */ filename?: string; library?: LibraryOptions; /** 表示作为 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 | string; /** *软件包名称,用于从描述文件中确定所需的版本。仅当无法根据请求自动确定包名称时才需要。 */ packageName?: string; /** *共享范围中来自模块的版本要求。 */ requiredVersion?: number | string; /** *在共享范围内的此键下查找模块。 */ shareKey?: string; /** *共享范围名称。 */ shareScope?: string; /** *在共享范围内仅允许共享模块的单个版本(默认情况下处于禁用状态)。 */ singleton?: boolean; /** *如果版本无效,则不接受共享模块(默认为是,如果本地后备模块可用并且共享模块不是单例,否则为no,如果未指定所需的版本,则无效)。 */ strictVersion?: boolean; /** *所提供模块的版本。将替换较低的匹配版本,但不会替换较高的版本。 */ version?: number | string; } export type SourceMapDevToolPluginOptions = NonNullable[0]>; export {};