UNPKG

taro-define-config

Version:

Provide a defineConfig function for tarojs config

1,697 lines (1,695 loc) 178 kB
import { Buffer } from "node:buffer"; import { URL as URL$1 } from "node:url"; import { Plugin as VitePlugin } from "vite"; import { OutputOptions as RollupOutputOptions, RollupOptions } from "rollup"; import webpack, { Compilation, Compiler, Configuration, LoaderContext } from "webpack"; import { Configuration as DevServerConfiguration } from "webpack-dev-server"; import WebpackChain from "webpack-chain"; import { SectionedSourceMapInput } from "@jridgewell/source-map"; import { Options as Options$2 } from "html-minifier-terser"; import { AsyncSeriesWaterfallHook } from "tapable"; //#region src/utils.d.ts /** * Promise or not */ type Awaitable<T> = PromiseLike<T> | T; /** * Array or not */ /** * Any function */ type AnyFn<T = unknown> = (...args: T[]) => T; /** * A literal type that supports custom further strings but preserves autocompletion in IDEs. * * @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609 */ type LiteralUnion<Union extends Base, Base = string> = Union | (Base & { zz_IGNORE_ME?: never; }); /** * Non empty object `{}` */ type NonEmptyObject<T> = T extends Record<string, never> ? never : T; /** * Exclude empty object properties from a type */ type ExcludeEmptyObjects<T> = { [K in keyof T]: NonEmptyObject<T[K]> }; //#endregion //#region src/config/cache.d.ts interface CacheBuildDependencies { config?: string[]; } interface Cache { /** * 是否开启持久化缓存 * * @see https://nervjs.github.io/taro-docs/docs/config-detail#cacheenable */ enable?: boolean; /** * 缓存子目录的名称 * * @see https://nervjs.github.io/taro-docs/docs/config-detail#cachename * @default `process.env.NODE_ENV-process.env.TARO_ENV` */ name?: string; /** * 当依赖的文件或该文件的依赖改变时,使缓存失效 * * @see https://webpack.js.org/configuration/cache/#cachebuilddependencies */ buildDependencies?: CacheBuildDependencies; } //#endregion //#region src/config/packages/less.d.ts interface LessSourceMap { outputFilename?: string; sourceMapRootpath?: string; sourceMapBasepath?: string; outputSourceFiles?: boolean; sourceMapFileInline?: boolean; sourceMapURL?: string; } interface LessOptions { /** * Source map options */ sourceMap?: LessSourceMap; /** * Filename of the main file to be passed to less.render() */ filename?: string; /** * The locations for less looking for files in @import rules */ paths?: string[]; /** * True, if run the less parser and just reports errors without any output */ lint?: boolean; /** * Pre-load global Less.js plugins */ plugins?: AnyFn[]; strictImports?: boolean; /** * If true, allow imports from insecure https hosts */ insecure?: boolean; depends?: boolean; maxLineLen?: number; /** * Add a path to every generated import and url in output css files */ rootpath?: string; /** * allows you to rewrite URLs in imported files so that the URL is always relative to the base file that has been passed to Less * * @see https://lesscss.org/usage/#less-options-rewrite-urls * @default `off` */ rewriteUrls?: LiteralUnion<'all' | 'local' | 'off'>; /** * Math mode options for avoiding symbol conflicts on math expressions * @description * - `always` (3.x default) - Less does math eagerly * - `parens-division` (4.0 default) - No division is performed outside of parens using / operator (but can be "forced" outside of parens with ./ operator - ./ is deprecated) * - `parens` | `strict` - Parens required for all math expressions * - `strict-legacy` (removed in 4.0) - In some cases, math will not be evaluated if any part of the expression cannot be evaluated */ math?: 'always' | 'parens-division' | 'parens' | 'strict-legacy' | 'strict'; /** * If true, stops any warnings from being shown */ silent?: boolean; /** * Without this option, Less attempts to guess at the output unit when it does maths * * @default false */ strictUnits?: boolean; /** * Defines a variable that can be referenced by the file */ globalVars?: Record<string, string>; /** * Puts Var declaration at the end of base file */ modifyVars?: Record<string, string>; /** * This option allows you to specify a argument to go on to every URL, This may be used for cache-busting for instance */ urlArgs?: string; /** * Read files synchronously in Node.js */ syncImport?: boolean; /** * If false, No color in compiling * * @deprecated */ color?: boolean; /** * @deprecated * @default false */ ieCompat?: boolean; /** * If true, compress using less built-in compression * * @deprecated use a third-party tool instead */ compress?: boolean; /** * @deprecated use `math` instead */ strictMath?: boolean; /** * @deprecated use `{ rewriteUrls: 'all' }` instead */ relativeUrls?: boolean; /** * Whether output file information and line numbers in compiled CSS code * * @deprecated */ dumpLineNumbers?: 'all' | 'comments' | 'mediaquery' | string; /** * If true, enable evaluation of JavaScript inline in `.less` files * * @deprecated use `plugins` instead */ javascriptEnabled?: boolean; [key: string]: any; } //#endregion //#region src/config/packages/sass.d.ts /** * All of the deprecation types currently used by Sass. * * Any of these IDs or the deprecation objects they point to can be passed to * `fatalDeprecations`, `futureDeprecations`, or `silenceDeprecations`. */ interface Deprecations { /** * Deprecation for passing a string directly to meta.call(). * * This deprecation was active in the first version of Dart Sass. */ 'call-string': Deprecation<'call-string'>; /** * Deprecation for @elseif. * * This deprecation became active in Dart Sass 1.3.2. */ elseif: Deprecation<'elseif'>; /** * Deprecation for @-moz-document. * * This deprecation became active in Dart Sass 1.7.2. */ 'moz-document': Deprecation<'moz-document'>; /** * Deprecation for imports using relative canonical URLs. * * This deprecation became active in Dart Sass 1.14.2. */ 'relative-canonical': Deprecation<'relative-canonical'>; /** * Deprecation for declaring new variables with !global. * * This deprecation became active in Dart Sass 1.17.2. */ 'new-global': Deprecation<'new-global'>; /** * Deprecation for using color module functions in place of plain CSS functions. * * This deprecation became active in Dart Sass 1.23.0. */ 'color-module-compat': Deprecation<'color-module-compat'>; /** * Deprecation for / operator for division. * * This deprecation became active in Dart Sass 1.33.0. */ 'slash-div': Deprecation<'slash-div'>; /** * Deprecation for leading, trailing, and repeated combinators. * * This deprecation became active in Dart Sass 1.54.0. */ 'bogus-combinators': Deprecation<'bogus-combinators'>; /** * Deprecation for ambiguous + and - operators. * * This deprecation became active in Dart Sass 1.55.0. */ 'strict-unary': Deprecation<'strict-unary'>; /** * Deprecation for passing invalid units to built-in functions. * * This deprecation became active in Dart Sass 1.56.0. */ 'function-units': Deprecation<'function-units'>; /** * Deprecation for using !default or !global multiple times for one variable. * * This deprecation became active in Dart Sass 1.62.0. */ 'duplicate-var-flags': Deprecation<'duplicate-var-flags'>; /** * Deprecation for passing null as alpha in the JS API. * * This deprecation became active in Dart Sass 1.62.3. */ 'null-alpha': Deprecation<'null-alpha'>; /** * Deprecation for passing percentages to the Sass abs() function. * * This deprecation became active in Dart Sass 1.65.0. */ 'abs-percent': Deprecation<'abs-percent'>; /** * Deprecation for using the current working directory as an implicit load path. * * This deprecation became active in Dart Sass 1.73.0. */ 'fs-importer-cwd': Deprecation<'fs-importer-cwd'>; /** * Deprecation for function and mixin names beginning with --. * * This deprecation became active in Dart Sass 1.76.0. */ 'css-function-mixin': Deprecation<'css-function-mixin'>; /** * Deprecation for declarations after or between nested rules. * * This deprecation became active in Dart Sass 1.77.7. */ 'mixed-decls': Deprecation<'mixed-decls'>; /** * Deprecation for meta.feature-exists * * This deprecation became active in Dart Sass 1.78.0. */ 'feature-exists': Deprecation<'feature-exists'>; /** * Deprecation for certain uses of built-in sass:color functions. * * This deprecation became active in Dart Sass 1.79.0. */ 'color-4-api': Deprecation<'color-4-api'>; /** * Deprecation for using global color functions instead of sass:color. * * This deprecation became active in Dart Sass 1.79.0. */ 'color-functions': Deprecation<'color-functions'>; /** * Deprecation for legacy JS API. * * This deprecation became active in Dart Sass 1.79.0. */ 'legacy-js-api': Deprecation<'legacy-js-api'>; /** * Deprecation for @import rules. * * This deprecation became active in Dart Sass 1.80.0. */ import: Deprecation<'import'>; /** * Deprecation for global built-in functions that are available in sass: modules. * * This deprecation became active in Dart Sass 1.80.0. */ 'global-builtin': Deprecation<'global-builtin'>; /** * Used for any user-emitted deprecation warnings. */ 'user-authored': Deprecation<'user-authored', 'user'>; } /** * Either a deprecation or its ID, either of which can be passed to any of * the relevant compiler options. * * @category Messages * @compatibility dart: 1.85.1, node: false */ type DeprecationOrId = Deprecation | keyof Deprecations; /** * The possible statuses that each deprecation can have. * * "active" deprecations are currently emitting deprecation warnings. * "future" deprecations are not yet active, but will be in the future. * "obsolete" deprecations were once active, but no longer are. * * The only "user" deprecation is "user-authored", which is used for deprecation * warnings coming from user code. */ type DeprecationStatus = 'active' | 'future' | 'obsolete' | 'user'; /** * A deprecated feature in the language. */ interface Deprecation<id extends keyof Deprecations = keyof Deprecations, status extends DeprecationStatus = DeprecationStatus> { /** The unique ID of this deprecation. */ id: id; /** The current status of this deprecation. */ status: status; /** A human-readable description of this deprecation. */ description?: string; /** The version this deprecation first became active in. */ deprecatedIn: status extends 'future' | 'user' ? null : Version; /** The version this deprecation became obsolete in. */ obsoleteIn: status extends 'obsolete' ? Version : null; } /** * A semantic version of the compiler. */ declare class Version { /** * Constructs a new version. * * All components must be non-negative integers. * * @param major - The major version. * @param minor - The minor version. * @param patch - The patch version. */ constructor(major: number, minor: number, patch: number); readonly major: number; readonly minor: number; readonly patch: number; /** * Parses a version from a string. * * This throws an error if a valid version can't be parsed. * * @param version - A string in the form "major.minor.patch". */ static parse(version: string): Version; } type CallbackValue = boolean | number | string | Array<boolean | number | string> | Record<PropertyKey, any>; type Context = { options: NodeSassOptions; callback?: (result: CallbackValue) => void; [data: string]: any; }; interface AsyncContext extends Context { callback: (result: CallbackValue) => void; } interface SyncContext extends Context { callback: undefined; } type ImporterReturnType = Error | { contents: string; file?: string; } | { file: string; } | null; type AsyncImporter = (this: AsyncContext, url: string, prev: string, done: (data: ImporterReturnType) => void) => void; type SyncImporter = (this: SyncContext, url: string, prev: string) => ImporterReturnType; type SourceSpan = { text: string; url: URL$1; context?: string; end: { column: number; line: number; offset: number; }; start: { column: number; line: number; offset: number; }; }; type LoggerWarnOptions = { span?: SourceSpan; stack?: string; } & ({ deprecation: false; } | { deprecation: true; deprecationType: Deprecation; }); interface SassLogger { /** * If this is `undefined`, Sass will print warnings to standard error */ warn(message: string, options: {}): void; /** * If this is `undefined`, Sass will print debug messages to standard error */ debug(message: string, options: { span: SourceSpan; }): void; } declare const nodePackageImporterKey: unique symbol; declare class NodePackageImporter { private readonly [nodePackageImporterKey]; constructor(entryPointDirectory?: string); } /** * Taro 配置项中 `sass` 配置 * * @see https://nervjs.github.io/taro-docs/docs/config-detail/#sass */ interface TaroSassOptions { /** * 需要全局注入的 `scss` 文件的绝对路径 * 当存在 {@link projectDirectory} 配置时,才支持传入相对路径 * * @see https://nervjs.github.io/taro-docs/docs/config-detail#sassresource */ resource?: string | string[]; /** * 项目根目录的绝对地址(若为小程序云开发模板,则应该是 `client` 目录) * * @see https://nervjs.github.io/taro-docs/docs/config-detail#sassprojectdirectory */ projectDirectory?: string; /** * 全局 `scss` 变量,优先级高于 `resource` * * @see https://nervjs.github.io/taro-docs/docs/config-detail#sassdata */ data?: string; [key: string]: any; } interface CommonSassOptions { /** * Path to a file to compile * @description `unavailable` and will be ignored */ file?: string; /** * Handles when LibSass encounters the \@import directive * * @experimental */ importer?: Array<AsyncImporter | SyncImporter> | AsyncImporter | SyncImporter; /** * holds a collection of custom functions that may be invoked by the sass files being compiled * * @experimental */ functions?: Record<string, AnyFn>; /** * `true` values disable the inclusion of source map information in the output file * * @default false */ omitSourceMapUrl?: boolean; /** * Enables source map generation during render and renderSync */ sourceMap?: boolean | string; /** * `true` includes the contents in the source map information * * @default false */ sourceMapContents?: boolean; /** * `true` embeds the source map as a data URI * * @default false */ sourceMapEmbed?: boolean; /** * the value will be emitted as `sourceRoot` in the source map information */ sourceMapRoot?: string; } /** * `node-sass` 配置, `sass-loader` 仅支持部分配置 * * @see https://www.npmjs.com/package/@types/node-sass?activeTab=code * @compatibility 9.0.0 * @deprecated */ interface NodeSassOptions extends CommonSassOptions { /** * A string to pass to compile * @description `unavailable` and will be ignored */ data?: string; /** * An array of paths that LibSass can look in to attempt to resolve your \@import declarations */ includePaths?: string[]; /** * true values enable Sass Indented Syntax for parsing the data string or file * * @default false */ indentedSyntax?: boolean; /** * Specify the intended location of the output file */ outFile?: string | null; /** * Determines the output format of the final CSS style * * @default `nested` */ outputStyle?: LiteralUnion<'compact' | 'compressed' | 'expanded' | 'nested'>; /** * determine whether to use space or tab character for indentation * * @default `space` */ indentType?: LiteralUnion<'space' | 'tab'>; /** * determine the number of spaces or tabs to be used for indentation, max is 10 * * @default 2 */ indentWidth?: number; /** * determine whether to use cr, crlf, lf or lfcr sequence for line break * * @default `lf` */ linefeed?: LiteralUnion<'cf' | 'crlf' | 'if' | 'lfcr'>; /** * determine how many digits after the decimal will be allowed * * @default 5 */ precision?: number; /** * Enables the line number and file where a selector is defined to be emitted into the compiled CSS as a comment * * @default false */ sourceComments?: boolean; [key: string]: any; } /** * `dart-sass` 配置, `sass-loader` 仅支持部分配置 * * @see https://github.com/sass/dart-sass * @see https://www.npmjs.com/package/sass?activeTab=code * @compatibility 1.89.1 */ interface DartSassOptions extends CommonSassOptions { /** * A string to pass to compile * `unavailable` and will be ignored */ data?: never; /** * Paths in which to look for stylesheets loaded by rules like \@use and \@import. */ loadPaths?: string[]; /** * Specify the intended location of the output file */ outFile?: string; /** * Determines the output format of the final CSS style * * @default `expanded` * @deprecated use `style` instead */ outputStyle?: LiteralUnion<'compressed' | 'expanded'>; /** * Determines the output format of the final CSS style * * @default `expanded` */ style?: LiteralUnion<'compressed' | 'expanded'>; /** * By default, if the CSS document contains non-ASCII characters, Sass adds a * `@charset` declaration (in expanded output mode) or a byte-order mark (in * compressed mode) to indicate its encoding to browsers or other consumers. * If `charset` is `false`, these annotations are omitted * * @default true */ charset?: boolean; /** * If this option is set to `true`, Sass won’t print warnings that are caused * by dependencies * * @default false */ quietDeps?: boolean; /** * A set of deprecations to treat as fatal */ fatalDeprecations?: (DeprecationOrId | Version)[]; /** * A set of future deprecations to opt into early */ futureDeprecations?: DeprecationOrId[]; /** * A set of active deprecations to ignore */ silenceDeprecations?: DeprecationOrId[]; /** * By default, Dart Sass will print only five instances of the same * deprecation warning per compilation to avoid deluging users in console * noise. If you set `verbose` to `true`, it will instead print every * deprecation warning it encounters * * @default false */ verbose?: boolean; /** * An object to use to handle warnings and/or debug messages from Sass */ logger?: SassLogger; /** * If this option is set to an instance of `NodePackageImporter`, Sass will * use the built-in Node.js package importer to resolve Sass files with a * `pkg:` URL scheme. */ pkgImporter?: NodePackageImporter; /** * If this is true, the compiler will exclusively use ASCII characters in its error and warning * messages. Otherwise, it may use non-ASCII Unicode characters as well. * * @default false */ alertAscii?: boolean; /** * If this is true, the compiler will use ANSI color escape codes in its error and warning * messages. If it's false, it won't use these. If it's undefined, the compiler will determine * whether or not to use colors depending on whether the user is using an interactive terminal. * * @default false */ alertColor?: boolean; /** * Whether Sass should include the sources in the generated source map. * This option has no effect if sourceMap is false. * * @default false */ sourceMapIncludeSources?: boolean; [key: string]: any; } //#endregion //#region src/config/packages/stylus.d.ts type StylusOptionsDefineItem = [string, boolean | number | string, boolean?]; interface StylusOptions { /** * Specify Stylus plugins to use */ use?: (string | AnyFn)[]; /** * Add path(s) to the import lookup paths */ include?: string[]; /** * Import the specified Stylus files/paths */ import?: string[]; /** * Define Stylus variables or functions * @default {} */ define?: Record<string, boolean | number | string> | StylusOptionsDefineItem[]; /** * Include regular CSS on \@import * @default false */ includeCSS?: boolean; /** * Emits comments in the generated CSS indicating the corresponding Stylus line * @default false */ lineNumbers?: boolean; /** * Move \@import and \@charset to the top * @default false */ hoistAtrules?: boolean; [key: string]: any; } //#endregion //#region src/config/packages/cssnano.d.ts type CSSNanoConfig<T> = T | [T, Record<string, any>] | [T]; interface CSSNanoOptions { /** * @see https://cssnano.github.io/cssnano/docs/config-file/#choose-a-preset */ preset?: CSSNanoConfig<AnyFn> | CSSNanoConfig<string>; /** * @see https://cssnano.github.io/cssnano/docs/config-file/#use-individual-plugins */ plugins?: (CSSNanoConfig<AnyFn> | CSSNanoConfig<string>)[] | CSSNanoConfig<AnyFn> | CSSNanoConfig<string>; /** * @see https://github.com/cssnano/cssnano/blob/master/packages/cssnano/types/index.d.ts */ configFile?: string; } //#endregion //#region src/config/packages/webpack.d.ts type Webpack = typeof webpack; type WebpackCompilation = Compilation; type WebpackCompiler = Compiler; type WebpackConfiguration = Configuration; type WebpackLoaderContext<T = any> = LoaderContext<T>; //#endregion //#region src/config/packages/css-loader.d.ts interface CSSLoaderUrl { filter: (url: string, resourcePath: string) => boolean; } interface CSSLoaderImport { filter: (url: string, media: string, resourcePath: string, supports?: string, layer?: string) => boolean; } type CSSLoaderModulesUnion = LiteralUnion<'global' | 'icss' | 'local' | 'pure'>; type CSSLoaderModulesExportLocalsConvention = LiteralUnion<'as-is' | 'asIs' | 'camel-case-only' | 'camel-case' | 'camelCase' | 'camelCaseOnly' | 'dashes-only' | 'dashes' | 'dashesOnly'>; interface CSSLoaderModulesObject { /** * @see https://github.com/webpack-contrib/css-loader#auto */ auto?: boolean | RegExp | ((resourcePath: string, resourceQuery: string, resourceFragment: string) => boolean); /** * @see https://github.com/webpack-contrib/css-loader#mode * @default `local` */ mode?: CSSLoaderModulesUnion | ((resourcePath: string, resourceQuery: string, resourceFragment: string) => CSSLoaderModulesUnion); /** * @see https://github.com/webpack-contrib/css-loader#localidentname * @default `hash:base64` */ localIdentName?: string; /** * @see https://github.com/webpack-contrib/css-loader#localidentcontext * @default `compiler.context` */ localIdentContext?: string; /** * @see https://github.com/webpack-contrib/css-loader#localidenthashsalt */ localIdentHashSalt?: string; /** * @see https://github.com/webpack-contrib/css-loader#localidenthashfunction * @default `md4` */ localIdentHashFunction?: string; /** * @see https://github.com/webpack-contrib/css-loader#localidenthashdigest * @default `hex` */ localIdentHashDigest?: string; /** * @see https://github.com/webpack-contrib/css-loader#localidenthashdigestlength * @default 20 */ localIdentHashDigestLength?: number; /** * @see https://github.com/webpack-contrib/css-loader#localidentregexp */ localIdentRegExp?: string | RegExp; /** * @see https://github.com/webpack-contrib/css-loader#getlocalident */ getLocalIdent?: (loaderContext: WebpackLoaderContext, localIdentName: string, localName: string) => string; /** * @see https://github.com/webpack-contrib/css-loader#namedexport */ namedExport?: boolean; /** * @see https://github.com/webpack-contrib/css-loader#exportglobals */ exportGlobals?: boolean; /** * @see https://github.com/webpack-contrib/css-loader#exportlocalsconvention */ exportLocalsConvention?: CSSLoaderModulesExportLocalsConvention | ((name: string) => string); /** * @see https://github.com/webpack-contrib/css-loader#exportonlylocals */ exportOnlyLocals?: boolean; /** * @see https://github.com/webpack-contrib/css-loader#getjson */ getJSON?: ({ resourcePath, imports, exports, replacements }: { resourcePath: string; exports: Array<{ name: string; value: string; }>; imports: Array<{ icss: boolean; importName: string; index: number; type: string; url: string; }>; replacements: Array<{ importName: string; localName: string; replacementName: string; }>; }) => Awaitable<void>; } type CSSLoaderExportType = LiteralUnion<'array' | 'css-style-sheet' | 'string'>; interface CSSLoaderOptions { /** * @see https://github.com/webpack-contrib/css-loader#url * @default true */ url?: boolean | CSSLoaderUrl; /** * @see https://github.com/webpack-contrib/css-loader#import * @default true */ import?: boolean | CSSLoaderImport; /** * @see https://github.com/webpack-contrib/css-loader#modules */ modules?: boolean | CSSLoaderModulesObject | CSSLoaderModulesUnion; /** * @see https://github.com/webpack-contrib/css-loader#sourcemap * @default compiler.devtool */ sourceMap?: boolean; /** * @see https://github.com/webpack-contrib/css-loader#importloaders * @default 0 */ importLoaders?: number; /** * @see https://github.com/webpack-contrib/css-loader#esmodule * @default true */ esModule?: boolean; /** * @see https://github.com/webpack-contrib/css-loader#exporttype * @default `array` */ exportType?: CSSLoaderExportType; [key: string]: any; } //#endregion //#region src/config/packages/url-loader.d.ts /** * `url-loader` 配置 * * @see https://github.com/webpack-contrib/url-loader#options * @compatibility 4.1.1 * @deprecated */ interface URLLoaderOptions { /** * Specify the name of the chunk */ name?: string | ((moduleId: string) => string); /** * Specifying the maximum size of a file in bytes * * @see https://github.com/webpack-contrib/url-loader#limit * @default true */ limit?: boolean | number | string; /** * Sets the MIME type for the file to be transformed * * @see https://github.com/webpack-contrib/url-loader#mimetype */ mimetype?: boolean | string; /** * Specify the encoding which the file will be inlined with * * @see https://github.com/webpack-contrib/url-loader#encoding * @default `base64` */ encoding?: boolean | string; /** * You can create you own custom implementation for encoding data. * * @see https://github.com/webpack-contrib/url-loader#generator */ generator?: (mimetype: string, encoding: string, content: string, resourcePath: string) => string; /** * Specifies an alternative loader to use when a target file's size exceeds the limit * * @see https://github.com/webpack-contrib/url-loader#fallback * @default `file-loader` */ fallback?: string; /** * Use ES modules syntax * * @see https://github.com/webpack-contrib/url-loader#esmodule * @default true */ esModule?: boolean; [key: string]: any; } //#endregion //#region src/config/packages/less-loader.d.ts interface LessLoaderOptions { /** * less options in camelCase, default value is `{ relativeUrls: true }` * * @see https://github.com/webpack-contrib/less-loader#lessoptions */ lessOptions?: LessOptions | ((loaderConext: WebpackLoaderContext) => LessOptions); /** * prepends/appends Less code to the actual entry file * * @see https://github.com/webpack-contrib/less-loader#additionaldata */ additionalData?: LoaderAdditionalData<'less'>; /** * if generation of source maps * * @see https://github.com/webpack-contrib/less-loader#sourcemap * @default compiler.devtool */ sourceMap?: boolean; /** * enables/disables the default webpack importer * * @see https://github.com/webpack-contrib/less-loader#webpackimporter * @default true */ webpackImporter?: 'only' | boolean; /** * determines which implementation of Less to use * * @see https://github.com/webpack-contrib/less-loader#implementation */ implementation?: string | Record<string, any>; /** * warnings and errors will be webpack warnings and errors, not just logs * * @see https://github.com/webpack-contrib/less-loader#lesslogaswarnorerr * @default false */ lessLogAsWarnOrErr?: boolean; [key: string]: any; } //#endregion //#region src/config/packages/postcss-url.d.ts type PostCSSUrlUrl = LiteralUnion<'copy' | 'inline' | 'rebase'>; interface PostCSSUrlUrlAsset { url: string; pathname?: string; absolutePath?: string; relativePath?: string; search?: string; hash?: string; } interface PostCSSUrlUrlDir { from?: string; to?: string; file?: string; } type PostcssUrlHashOptionsMethod = LiteralUnion<'xxhash32' | 'xxhash64'>; interface PostcssUrlHashOptions { method?: PostcssUrlHashOptionsMethod | ((file: Buffer) => string); shrink?: number; append?: boolean; } interface PostcssUrlOptions { /** * @see https://github.com/postcss/postcss-url#url * @default `rebase` */ url?: PostCSSUrlUrl | ((asset: PostCSSUrlUrlAsset, dir: PostCSSUrlUrlDir) => string); /** * @see https://github.com/postcss/postcss-url#maxsize */ maxSize?: number; /** * @see https://github.com/postcss/postcss-url#ignorefragmentwarning * @default false */ ignoreFragmentWarning?: boolean; /** * @default false */ optimizeSvgEncode?: boolean; /** * @see https://github.com/postcss/postcss-url#filter */ filter?: string | RegExp | ((file: string) => boolean); /** * @see https://github.com/postcss/postcss-url#includeurifragment * @default false */ includeUriFragment?: boolean; /** * @see https://github.com/postcss/postcss-url#fallback */ fallback?: (asset: PostCSSUrlUrlAsset, dir: PostCSSUrlUrlDir) => string; /** * @see https://github.com/postcss/postcss-url#basepath */ basePath?: string | string[]; /** * @see https://github.com/postcss/postcss-url#assetspath * @default false */ assetsPath?: boolean | string; /** * @see https://github.com/postcss/postcss-url#usehash * @default false */ useHash?: boolean; /** * @see https://github.com/postcss/postcss-url#hashoptions */ hashOptions?: PostcssUrlHashOptions; [key: string]: any; } //#endregion //#region src/config/packages/sass-loader.d.ts type SassLoaderSassOptions = DartSassOptions | NodeSassOptions; interface SassLoaderOptions { /** * determines which implementation of Sass to use * * @see https://github.com/webpack-contrib/sass-loader#implementation * @default `sass` */ implementation?: object | string; /** * Options for Dart Sass or Node Sass implementation * * @see https://github.com/webpack-contrib/sass-loader#sassoptions */ sassOptions?: SassLoaderSassOptions | ((content: string | Buffer, loaderContext: WebpackLoaderContext, meta: any) => SassLoaderSassOptions); /** * Enables/Disables generation of source maps * * @see https://github.com/webpack-contrib/sass-loader#sourcemap * @default compiler.devtool */ sourceMap?: boolean; /** * Prepends Sass/SCSS code before the actual entry file. In this case, the sass-loader will not override the data option but just prepend the entry's content * * @see https://github.com/webpack-contrib/sass-loader#additionaldata */ additionalData?: LoaderAdditionalData<'sass'>; /** * Enables/Disables the default webpack importer * * @see https://github.com/webpack-contrib/sass-loader#webpackimporter * @default true */ webpackImporter?: boolean; /** * Treats the @warn rule as a webpack warning * * @see https://github.com/webpack-contrib/sass-loader#warnruleaswarning * @default false */ warnRuleAsWarning?: boolean; /** * Allows you to switch between the legacy and modern APIs * * @see https://github.com/webpack-contrib/sass-loader#api * @see https://sass-lang.com/documentation/js-api/ * @default `modern` for `sass (dart-sass)` and `sass-embedded`, or `legacy` for `node-sass` */ api?: LiteralUnion<'legacy' | 'modern-compiler' | 'modern'>; [key: string]: any; } //#endregion //#region src/config/packages/autoprefixer.d.ts /** * `autoprefixer` 配置 * * @see https://github.com/postcss/autoprefixer/blob/main/lib/autoprefixer.d.ts * @compatibility 10.4.21 */ interface AutoprefixerOptions { /** * environment for `Browserslist` */ env?: string; /** * should Autoprefixer use Visual Cascade, if CSS is uncompressed * * @default true */ cascade?: boolean; /** * should Autoprefixer add prefixes * * @default true */ add?: boolean; /** * should Autoprefixer [remove outdated] prefixes * * @default true */ remove?: boolean; /** * should Autoprefixer add prefixes for `@supports` parameters * * @default true */ supports?: boolean; /** * should Autoprefixer add prefixes for flexbox properties * * @default true */ flexbox?: 'no-2009' | boolean; /** * should Autoprefixer add IE 10-11 prefixes for Grid Layout properties * @description * - false (default): prevent Autoprefixer from outputting CSS Grid translations * - "autoplace": enable Autoprefixer grid translations and include autoplacement support. You can also use /* autoprefixer grid: autoplace *\/ in your CSS * - "no-autoplace": enable Autoprefixer grid translations but exclude autoplacement support. You can also use /* autoprefixer grid: no-autoplace *\/ in your CSS. (alias for the deprecated true value) * * @default false */ grid?: 'autoplace' | 'no-autoplace' | boolean; /** * custom usage statistics for > 10% in my stats browsers query */ stats?: Record<string, any>; /** * list of queries for target browsers * * @description Try to not use it. The best practice is to use `.browserslistrc` config or `browserslist` key in `package.json` to share target browsers with Babel, ESLint and Stylelint * * @see https://github.com/browserslist/browserslist#queries * @default ['defaults'] */ overrideBrowserslist?: string | string[]; /** * do not raise error on unknown browser version in `Browserslist` config * * @default false */ ignoreUnknownVersions?: boolean; } //#endregion //#region src/config/packages/style-loader.d.ts type StyleLoaderInjectType = LiteralUnion<'autoStyleTag' | 'lazyAutoStyleTag' | 'lazySingletonStyleTag' | 'lazyStyleTag' | 'linkTag' | 'singletonStyleTag' | 'styleTag'>; interface StyleLoaderOptions { /** * Allows to setup how styles will be injected into the DOM * * @see https://github.com/webpack-contrib/style-loader#injecttype * @default `styleTag` */ injectType?: StyleLoaderInjectType; /** * attach given attributes with their values on <style> / <link> element * * @see https://github.com/webpack-contrib/style-loader#attributes */ attributes?: Record<string, string>; /** * @see https://github.com/webpack-contrib/style-loader#insert * @default `head` */ insert?: string | ((htmlElement: HTMLElement, options: Record<string, any>) => void); /** * @see https://github.com/webpack-contrib/style-loader#styleTagTransform */ styleTagTransform?: string | ((css: string, styleElement: HTMLStyleElement, options: Record<string, any>) => void); /** * @see https://github.com/webpack-contrib/style-loader#base */ base?: number; /** * @see https://github.com/webpack-contrib/style-loader#esmodule * @default true */ esModule?: boolean; [key: string]: any; } //#endregion //#region src/config/packages/stylus-loader.d.ts interface StylusOptionsResolveURL { paths?: string[]; nocheck?: boolean; } /** * @see https://github.com/webpack-contrib/stylus-loader#object */ interface StylusLoaderStylusOptions extends StylusOptions { resolveURL?: boolean | StylusOptionsResolveURL; compress?: boolean; paths?: string[]; } interface StylusLoaderOptions { /** * @see https://github.com/webpack-contrib/stylus-loader#stylusOptions * @default {} */ stylusOptions?: StylusLoaderStylusOptions | ((loaderContext: WebpackLoaderContext) => string[] | { paths: string[]; }); /** * @see https://github.com/webpack-contrib/stylus-loader#sourcemap */ sourceMap?: boolean; /** * @see https://github.com/webpack-contrib/stylus-loader#webpackimporter * @default true */ webpackImporter?: boolean; /** * @see https://github.com/webpack-contrib/stylus-loader#additionalData */ additionalData?: LoaderAdditionalData<'stylus'>; /** * @see https://github.com/webpack-contrib/stylus-loader#implementation */ implementation?: string | AnyFn; [key: string]: any; } //#endregion //#region src/config/packages/postcss-css-modules.d.ts declare class CustomLoader { constructor(root: string, plugins: any[]); fetch(file: string, relativeTo: string, depTrace: string): Promise<Record<string, string>>; finalSource?: string; } interface PostcssCssModulesOptions { getJSON?: (cssFilename: string, json: Record<string, string>, outputFilename: string) => void; /** * style of exported classnames, the keys in your json */ localsConvention?: LiteralUnion<'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly'> | ((originalClassName: string, generatedClassName: string, inputFile: string) => string); /** * change all the classes are local or global * * @default `local` */ scopeBehaviour?: LiteralUnion<'global' | 'local'>; /** * define paths for global modules */ globalModulePaths?: RegExp[]; /** * 转换模式,取值为 global/module */ namingPattern?: 'global' | string; /** * generate custom classes */ generateScopedName?: string | ((name: string, filename: string, css: string) => string); /** * add custom hash to generate more unique classes */ hashPrefix?: string; /** * export global names via the JSON object along with the local ones */ exportGlobals?: boolean; /** * root path */ root?: string; /** * use custom loader if needed */ Loader?: typeof CustomLoader; /** * resolve custom path alias */ resolve?: (file: string, importer: string) => string | Promise<string | null> | null; [key: string]: any; } //#endregion //#region src/config/design.d.ts interface DesignWidthInput { /** * 样式文件内容 */ css: string; /** * 样式文件路径 */ file?: string; hasBOM: boolean; } /** * @param input - 样式文件绝对路径 * * @returns 设计稿尺寸 */ type DesignWidth = number | ((input?: number | string | DesignWidthInput) => number); /** * 设计稿尺寸换算规则 */ type DesignRatio = Record<number | string, number>; //#endregion //#region src/config/packages/postcss-pxtransform.d.ts interface PostcssPxtransformOptions { /** * 目标平台 * * @default `weapp` */ platform?: LiteralUnion<'h5' | 'harmony' | 'quickapp' | 'rn' | 'weapp'>; /** * 设计稿尺寸 * * @default 750 */ designWidth?: DesignWidth; /** * 设计稿尺寸换算规则 */ deviceRatio?: DesignRatio; /** * @default 16 */ rootValue?: number; /** * @deprecated use `rootValue` instead */ root_value?: number; /** * `rem` 单位允许的小数位 * * @default 5 */ unitPrecision?: number; /** * @deprecated use `unitPrecision` instead */ unit_precision?: number; /** * 允许转换的属性列表 * * @default ['*'] */ propList?: string[]; /** * @deprecated use `propList` instead */ prop_white_list?: string[]; /** * @deprecated use `propList` instead */ propWhiteList?: string[]; /** * 黑名单里的选择器将会被忽略 * * @default [] */ selectorBlackList?: (string | RegExp)[]; /** * @deprecated use `selectorBlackList` instead */ selector_black_list?: (string | RegExp)[]; /** * 直接替换而不是追加一条进行覆盖 * * @default true */ replace?: boolean; /** * 允许媒体查询里的 px 单位转换 * * @default false */ mediaQuery?: boolean; /** * @deprecated use `mediaQuery` instead */ media_query?: boolean; /** * 设置一个可被转换的最小 px 值 * * @default 0 */ minPixelValue?: number; /** * H5 字体尺寸大小基准值,开发者可以自行调整单位换算的基准值 * * @description supported h5 only * @default 20 */ baseFontSize?: number; /** * H5 根节点 font-size 的最小值 * * @description supported h5 only * @default 20 */ minRootSize?: number; /** * H5 根节点 font-size 的最大值 * * @description supported h5 only * @default 40 */ maxRootSize?: number; /** * 设置 1px 是否需要被转换 * * @default false */ onePxTransform?: boolean; /** * 转换后的单位,当前仅支持小程序 (默认 `rpx`) 和 Web 端 (默认 `rem`) * @description Web 端使用 rem 单位时会注入脚本用于设置 body 上的 font-size 属性,其他单位无该操作 */ targetUnit?: LiteralUnion<'rem' | 'rpx' | 'vw'>; /** * 启用的能力 Scope * * @default ['platform', 'size'] */ methods?: string[]; /** * filter 回调函数,可 exclude 不处理的文件 */ exclude?: (fileName: string) => boolean; [key: string]: any; } //#endregion //#region src/config/packages/postcss-html-transform.d.ts type PostcssHtmlTransformPlatform = LiteralUnion<'h5' | 'mini-program' | 'quickapp' | 'rn'>; interface PostcssHtmlTransformOptions { /** * 目标构建平台 * * @see https://github.com/NervJS/taro/blob/884c799553df1682ef0996c59c7fbd77f60755c9/packages/postcss-html-transform/src/index.ts#L12 * @default `mini-program` */ platform?: PostcssHtmlTransformPlatform; /** * 是否移除鼠标样式, `h5` 平台默认为 `true` * * @see https://github.com/NervJS/taro/blob/884c799553df1682ef0996c59c7fbd77f60755c9/packages/postcss-html-transform/src/index.ts#L46 */ removeCursorStyle?: boolean; [key: string]: any; } //#endregion //#region src/config/packages/esbuild.d.ts /** * @file `esbuild` 类型 * * @see https://www.npmjs.com/package/esbuild?activeTab=code * @compatibility 0.25.5 */ type Platform = 'browser' | 'neutral' | 'node'; type Format = 'cjs' | 'esm' | 'iife'; type Loader = 'base64' | 'binary' | 'copy' | 'css' | 'dataurl' | 'default' | 'empty' | 'file' | 'js' | 'json' | 'jsx' | 'local-css' | 'text' | 'ts' | 'tsx'; type LogLevel = 'debug' | 'error' | 'info' | 'silent' | 'verbose' | 'warning'; type Charset = 'ascii' | 'utf8'; type Drop = 'console' | 'debugger'; interface CommonOptions { /** Documentation: https://esbuild.github.io/api/#sourcemap */ sourcemap?: 'both' | 'external' | 'inline' | 'linked' | boolean; /** Documentation: https://esbuild.github.io/api/#legal-comments */ legalComments?: 'eof' | 'external' | 'inline' | 'linked' | 'none'; /** Documentation: https://esbuild.github.io/api/#source-root */ sourceRoot?: string; /** Documentation: https://esbuild.github.io/api/#sources-content */ sourcesContent?: boolean; /** Documentation: https://esbuild.github.io/api/#format */ format?: Format; /** Documentation: https://esbuild.github.io/api/#global-name */ globalName?: string; /** Documentation: https://esbuild.github.io/api/#target */ target?: string | string[]; /** Documentation: https://esbuild.github.io/api/#supported */ supported?: Record<string, boolean>; /** Documentation: https://esbuild.github.io/api/#platform */ platform?: Platform; /** Documentation: https://esbuild.github.io/api/#mangle-props */ mangleProps?: RegExp; /** Documentation: https://esbuild.github.io/api/#mangle-props */ reserveProps?: RegExp; /** Documentation: https://esbuild.github.io/api/#mangle-props */ mangleQuoted?: boolean; /** Documentation: https://esbuild.github.io/api/#mangle-props */ mangleCache?: Record<string, false | string>; /** Documentation: https://esbuild.github.io/api/#drop */ drop?: Drop[]; /** Documentation: https://esbuild.github.io/api/#drop-labels */ dropLabels?: string[]; /** Documentation: https://esbuild.github.io/api/#minify */ minify?: boolean; /** Documentation: https://esbuild.github.io/api/#minify */ minifyWhitespace?: boolean; /** Documentation: https://esbuild.github.io/api/#minify */ minifyIdentifiers?: boolean; /** Documentation: https://esbuild.github.io/api/#minify */ minifySyntax?: boolean; /** Documentation: https://esbuild.github.io/api/#line-limit */ lineLimit?: number; /** Documentation: https://esbuild.github.io/api/#charset */ charset?: Charset; /** Documentation: https://esbuild.github.io/api/#tree-shaking */ treeShaking?: boolean; /** Documentation: https://esbuild.github.io/api/#ignore-annotations */ ignoreAnnotations?: boolean; /** Documentation: https://esbuild.github.io/api/#jsx */ jsx?: 'automatic' | 'preserve' | 'transform'; /** Documentation: https://esbuild.github.io/api/#jsx-factory */ jsxFactory?: string; /** Documentation: https://esbuild.github.io/api/#jsx-fragment */ jsxFragment?: string; /** Documentation: https://esbuild.github.io/api/#jsx-import-source */ jsxImportSource?: string; /** Documentation: https://esbuild.github.io/api/#jsx-development */ jsxDev?: boolean; /** Documentation: https://esbuild.github.io/api/#jsx-side-effects */ jsxSideEffects?: boolean; /** Documentation: https://esbuild.github.io/api/#define */ define?: { [key: string]: string; }; /** Documentation: https://esbuild.github.io/api/#pure */ pure?: string[]; /** Documentation: https://esbuild.github.io/api/#keep-names */ keepNames?: boolean; /** Documentation: https://esbuild.github.io/api/#color */ color?: boolean; /** Documentation: https://esbuild.github.io/api/#log-level */ logLevel?: LogLevel; /** Documentation: https://esbuild.github.io/api/#log-limit */ logLimit?: number; /** Documentation: https://esbuild.github.io/api/#log-override */ logOverride?: Record<string, LogLevel>; /** Documentation: https://esbuild.github.io/api/#tsconfig-raw */ tsconfigRaw?: string | TsconfigRaw; } interface TsconfigRaw { compilerOptions?: { alwaysStrict?: boolean; baseUrl?: string; experimentalDecorators?: boolean; importsNotUsedAsValues?: 'error' | 'preserve' | 'remove'; jsx?: 'preserve' | 'react-jsx' | 'react-jsxdev' | 'react-native' | 'react'; jsxFactory?: string; jsxFragmentFactory?: string; jsxImportSource?: string; paths?: Record<string, string[]>; preserveValueImports?: boolean; strict?: boolean; target?: string; useDefineForClassFields?: boolean; verbatimModuleSyntax?: boolean; }; } interface BuildOptions extends CommonOptions { /** Documentation: https://esbuild.github.io/api/#bundle */ bundle?: boolean; /** Documentation: https://esbuild.github.io/api/#splitting */ splitting?: boolean; /** Documentation: https://esbuild.github.io/api/#preserve-symlinks */ preserveSymlinks?: boolean; /** Documentation: https://esbuild.github.io/api/#outfile */ outfile?: string; /** Documentation: https://esbuild.github.io/api/#metafile */ metafile?: boolean; /** Documentation: https://esbuild.github.io/api/#outdir */ outdir?: string; /** Documentation: https://esbuild.github.io/api/#outbase */ outbase?: string; /** Documentation: https://esbuild.github.io/api/#external */ external?: string[]; /** Documentation: https://esbuild.github.io/api/#packages */ packages?: 'bundle' | 'external'; /** Documentation: https://esbuild.github.io/api/#alias */ alias?: Record<string, string>; /** Documentation: https://esbuild.github.io/api/#loader */ loader?: { [ext: string]: Loader; }; /** Documentation: https://esbuild.github.io/api/#resolve-extensions */ resolveExtensions?: string[]; /** Documentation: https://esbuild.github.io/api/#main-fields */ mainFields?: string[]; /** Documentation: https://esbuild.github.io/api/#conditions */ conditions?: string[]; /** Documentation: https://esbuild.github.io/api/#write */ write?: boolean; /** Documentation: https://esbuild.github.io/api/#allow-overwrite */ allowOverwrite?: boolean; /** Documentation: https://esbuild.github.io/api/#tsconfig */ tsconfig?: string; /** Documentation: https://esbuild.github.io/api/#out-extension */ outExtension?: { [ext: string]: string; }; /** Documentation: https://esbuild.github.io/api/#public-path */ publicPath?: string; /** Documentation: https://esbuild.github.io/api/#entry-names */ entryNames?: string; /** Documentation: https://esbuild.github.io/api/#chunk-names */ chunkNames?: string; /** Documentation: https://esbuild.github.io/api/#asset-names */ assetNames?: string; /** Documentation: https://esbuild.github.io/api/#inject */ inject?: string[]; /** Documentation: https://esbuild.github.io/api/#banner */ banner?: { [type: string]: string; }; /** Documentation: https://esbuild.github.io/api/#footer */ footer?: { [type: string]: string; }; /** Documentation: https://esbuild.github.io/api/#entry-points */ entryPoints?: { in: string; out: string; }[] | Record<string, string> | string[]; /** Documentation: https://esbuild.github.io/api/#stdin */ stdin?: StdinOptions; /** Documentation: https://esbuild.github.io/plugins/ */ plugins?: Plugin$2[]; /** Documentation: https://esbuild.github.io/api/#working-directory */ absWorkingDir?: string; /** Documentation: https://esbuild.github.io/api/#node-paths */ nodePaths?: string[]; } interface StdinOptions { contents: string | Uint8Array; resolveDir?: string; sourcefile?: string; loader?: Loader; } interface Message { id: string; pluginName: string; text: string; location: Location | null; notes: Note[]; /** * Optional user-specified data that is passed through unmodified. You can * use