@tarojs/taro 3.7.0-alpha.2 → 3.7.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/package.json +16 -3
  2. package/types/api/ad/index.d.ts +6 -18
  3. package/types/api/ai/inference.d.ts +129 -0
  4. package/types/api/ai/visionkit.d.ts +625 -54
  5. package/types/api/alipay/index.d.ts +43 -0
  6. package/types/api/base/crypto.d.ts +18 -4
  7. package/types/api/base/index.d.ts +2 -2
  8. package/types/api/base/performance.d.ts +65 -2
  9. package/types/api/base/system.d.ts +65 -0
  10. package/types/api/base/weapp/app-event.d.ts +18 -18
  11. package/types/api/canvas/index.d.ts +67 -54
  12. package/types/api/device/calendar.d.ts +2 -2
  13. package/types/api/device/screen.d.ts +61 -0
  14. package/types/api/device/sms.d.ts +26 -0
  15. package/types/api/media/audio.d.ts +50 -30
  16. package/types/api/media/image.d.ts +40 -17
  17. package/types/api/media/live.d.ts +52 -0
  18. package/types/api/media/video.d.ts +64 -23
  19. package/types/api/media/voip.d.ts +103 -0
  20. package/types/api/network/download.d.ts +2 -10
  21. package/types/api/network/request.d.ts +84 -24
  22. package/types/api/network/upload.d.ts +2 -10
  23. package/types/api/open-api/address.d.ts +12 -10
  24. package/types/api/open-api/channels.d.ts +31 -0
  25. package/types/api/open-api/device-voip.d.ts +63 -0
  26. package/types/api/open-api/login.d.ts +1 -1
  27. package/types/api/open-api/my-miniprogram.d.ts +2 -2
  28. package/types/api/open-api/privacy.d.ts +99 -0
  29. package/types/api/route/index.d.ts +3 -0
  30. package/types/api/share/index.d.ts +1 -1
  31. package/types/api/skyline/index.d.ts +59 -0
  32. package/types/api/storage/cache-manager.d.ts +198 -0
  33. package/types/api/taro.extend.d.ts +223 -0
  34. package/types/{taro.hooks.d.ts → api/taro.hooks.d.ts} +4 -4
  35. package/types/api/ui/navigation-bar.d.ts +1 -1
  36. package/types/compile/compiler.d.ts +8 -6
  37. package/types/compile/config/h5.d.ts +76 -9
  38. package/types/compile/config/mini.d.ts +80 -10
  39. package/types/compile/config/project.d.ts +242 -20
  40. package/types/compile/config/rn.d.ts +64 -0
  41. package/types/compile/config/util.d.ts +83 -11
  42. package/types/compile/hooks.d.ts +1 -1
  43. package/types/compile/viteCompilerContext.d.ts +128 -0
  44. package/types/global.d.ts +9 -8
  45. package/types/index.d.ts +9 -7
  46. package/types/taro.api.d.ts +11 -1
  47. package/types/taro.component.d.ts +3 -2
  48. package/types/taro.config.d.ts +122 -2
  49. package/types/taro.extend.d.ts +0 -112
@@ -1,6 +1,8 @@
1
1
  import type Webpack from 'webpack'
2
2
  import type Chain from 'webpack-chain'
3
- import type { IMINI_APP_FILE_TYPE, IOption, IPostcssOption } from './util'
3
+ import type { IOption, IPostcssOption, IUrlLoaderOption } from './util'
4
+ import type { OutputOptions as RollupOutputOptions } from 'rollup'
5
+ import type { CompilerTypes, CompilerWebpackTypes } from '../compiler'
4
6
 
5
7
  interface Runtime {
6
8
  enableInnerHTML: boolean
@@ -12,37 +14,105 @@ interface Runtime {
12
14
  enableMutationObserver: boolean
13
15
  }
14
16
 
15
- export interface IMiniAppConfig {
16
- appOutput?: boolean
17
+ interface OutputExt {
18
+ /**
19
+ * 编译前清空输出目录
20
+ * @since Taro v3.6.9
21
+ * @description
22
+ * - 默认清空输出目录,可设置 clean: false 不清空
23
+ * - 可设置 clean: { keep: ['project.config.json'] } 保留指定文件
24
+ * - 注意 clean.keep 不支持函数
25
+ */
26
+ clean?: boolean | {
27
+ /** 保留指定文件不删除 */
28
+ keep?: Array<string | RegExp> | string | RegExp
29
+ }
30
+ }
31
+
32
+ export interface IMiniAppConfig<T extends CompilerTypes = CompilerWebpackTypes> {
33
+ /** 默认值:'cheap-module-source-map', 具体参考[Webpack devtool 配置](https://webpack.js.org/configuration/devtool/#devtool) */
17
34
  sourceMapType?: string
35
+
36
+ /** 指定 React 框架相关的代码是否使用开发环境(未压缩)代码,默认使用生产环境(压缩后)代码 */
18
37
  debugReact?: boolean
38
+
39
+ /** 是否跳过第三方依赖 usingComponent 的处理,默认为自动处理第三方依赖的自定义组件 */
40
+ skipProcessUsingComponents?: boolean
41
+
42
+ /** 压缩小程序 xml 文件的相关配置 */
19
43
  minifyXML?: {
44
+ /** 是否合并 xml 文件中的空格 (默认false) */
20
45
  collapseWhitespace?: boolean
21
46
  }
22
47
 
48
+ /**
49
+ * 自定义 Webpack 配置
50
+ * @param chain [webpackChain](https://github.com/neutrinojs/webpack-chain) 对象
51
+ * @param webpack webpack 实例
52
+ * @param PARSE_AST_TYPE 小程序编译时的文件类型集合
53
+ * @returns
54
+ */
23
55
  webpackChain?: (chain: Chain, webpack: typeof Webpack, PARSE_AST_TYPE: any) => void
24
- output?: Webpack.Configuration['output']
25
- postcss?: IPostcssOption
56
+
57
+ /** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/)
58
+ * vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/)
59
+ */
60
+ output?: T extends 'vite'
61
+ ? Pick<RollupOutputOptions, 'chunkFileNames'> & OutputExt
62
+ : Webpack.Configuration['output'] & OutputExt
63
+
64
+ /** 配置 postcss 相关插件 */
65
+ postcss?: IPostcssOption<'mini'>
66
+
67
+ /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
26
68
  cssLoaderOption?: IOption
69
+
70
+ /** [sass-loader](https://github.com/webpack-contrib/sass-loader) 的附加配置 */
27
71
  sassLoaderOption?: IOption
72
+
73
+ /** [less-loader](https://github.com/webpack-contrib/less-loader) 的附加配置 */
28
74
  lessLoaderOption?: IOption
75
+
76
+ /** [stylus-loader](https://github.com/shama/stylus-loader) 的附加配置 */
29
77
  stylusLoaderOption?: IOption
30
- mediaUrlLoaderOption?: IOption
31
- fontUrlLoaderOption?: IOption
32
- imageUrlLoaderOption?: IOption
78
+
79
+ /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
80
+ mediaUrlLoaderOption?: IUrlLoaderOption
81
+
82
+ /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
83
+ fontUrlLoaderOption?: IUrlLoaderOption
84
+
85
+ /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
86
+ imageUrlLoaderOption?: IUrlLoaderOption
87
+
88
+ /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
33
89
  miniCssExtractPluginOption?: IOption
34
90
 
35
- customFilesTypes?: IMINI_APP_FILE_TYPE
91
+ /** 用于告诉 Taro 编译器需要抽取的公共文件 */
36
92
  commonChunks?: string[] | ((commonChunks: string[]) => string[])
37
- addChunkPages?: ((pages: Map<string, string[]>, pagesNames?: string[]) => void)
93
+
94
+ /** 为某些页面单独指定需要引用的公共文件 */
95
+ addChunkPages?: (pages: Map<string, string[]>, pagesNames?: string[]) => void
96
+
97
+ /** 优化主包的体积大小 */
38
98
  optimizeMainPackage?: {
39
99
  enable?: boolean
40
100
  exclude?: any[]
41
101
  }
42
102
 
103
+ /** 小程序编译过程的相关配置 */
43
104
  compile?: {
44
105
  exclude?: any[]
45
106
  include?: any[]
46
107
  }
108
+
109
+ /** 插件内部使用 */
47
110
  runtime?: Runtime
48
111
  }
112
+
113
+ export interface IMiniFilesConfig {
114
+ [configName: string]: {
115
+ content: any
116
+ path: string
117
+ }
118
+ }
@@ -1,95 +1,317 @@
1
1
  import type Webpack from 'webpack'
2
2
  import type Chain from 'webpack-chain'
3
- import type { Compiler } from '../compiler'
4
- import type { IModifyWebpackChain } from '../hooks'
5
- import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from "./util"
3
+ import { type Input } from 'postcss'
4
+ import type { Compiler, CompilerTypes, CompilerWebpackTypes } from '../compiler'
5
+ import type { IModifyChainData } from '../hooks'
6
+ import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from './util'
6
7
  import type { IH5Config } from './h5'
7
- import type { IMiniAppConfig } from './mini'
8
+ import type { IMiniAppConfig, IMiniFilesConfig } from './mini'
9
+ import type { IRNConfig } from './rn'
8
10
 
9
- export type PluginItem = string | [string, object]
11
+ export type PluginItem<T = object> = string | [string, T] | [string, () => T | Promise<T>]
10
12
 
11
13
  interface ICache {
14
+ /**
15
+ * 是否开启持久化缓存 (默认值 false)
16
+ * @description ```
17
+ * 值为 false 时:开发模式下 WebpackConfig.cache.type = 'memory',而生产模式下 WebpackConfig.cache = false;
18
+ * 值为 true 时:开发模式和生产模式下均为 WebpackConfig.cache.type = 'filesystem'
19
+ * ```
20
+ */
12
21
  enable?: boolean
22
+
23
+ /**
24
+ * 当依赖的文件或该文件的依赖改变时,使缓存失效。
25
+ * @description 详详情请参考 [WebpackConfig.cache.buildDependencies](https://webpack.js.org/configuration/cache/#cachebuilddependencies)。
26
+ */
13
27
  buildDependencies?: Record<string, any>
28
+
29
+ /**
30
+ * 缓存子目录的名称 (默认值 process.env.NODE_ENV-process.env.TARO_ENV)
31
+ * @description 详情请参考 [WebpackConfig.cache.name](https://webpack.js.org/configuration/cache/#cachename)
32
+ */
14
33
  name?: string
15
34
  }
16
35
 
17
36
  interface ILogger {
37
+ /** 是否简化输出日志 (默认值 true)*/
18
38
  quiet: boolean
39
+ /** 是否输出 Webpack Stats 信息 (默认值 false) */
19
40
  stats: boolean
20
41
  }
21
42
 
22
43
  export interface IProjectBaseConfig {
23
44
  isWatch?: boolean
24
45
  port?: number
46
+ /** 项目名称 */
25
47
  projectName?: string
48
+
49
+ /** 项目创建日期 */
26
50
  date?: string
27
- designWidth?: number | ((size: number) => number)
51
+
52
+ /** 设计稿尺寸 */
53
+ designWidth?: number | ((size?: string | number | Input) => number)
54
+
55
+ /** 设计稿尺寸换算规则 */
28
56
  deviceRatio?: TaroGeneral.TDeviceRatio
57
+
29
58
  watcher?: any[]
59
+
60
+ /** 源码存放目录 (默认值:'src') */
30
61
  sourceRoot?: string
62
+
63
+ /** 代码编译后的生产目录 (默认值:'dist') */
31
64
  outputRoot?: string
65
+
66
+ /**
67
+ * 用于配置`process.env.xxxx`相关的环境变量
68
+ * @deprecated 建议使用根目录下的 .env 文件替代
69
+ * @description 注意:这里的环境变量只能在业务代码中使用,编译时的 node 环境中无法使用
70
+ * @example
71
+ * ```ts
72
+ * // config/index.ts
73
+ * export default defineConfig({
74
+ * env: {
75
+ * xxxx: '"测试"'
76
+ * }
77
+ * })
78
+ *
79
+ * // src/app.ts
80
+ * onShow() {
81
+ * console.log(process.env.xxxx) // 打印 "测试"
82
+ * }
83
+ * ```
84
+ */
32
85
  env?: IOption
86
+
87
+ /** 用于配置目录别名,从而方便书写代码引用路径 */
33
88
  alias?: IOption
89
+
90
+ /**
91
+ * 用于配置一些常量供代码中进行全局替换使用
92
+ * @description 注意:这里的环境变量只能在业务代码中使用,编译时的 node 环境中无法使用
93
+ * @example
94
+ * ```ts
95
+ * // config/index.ts
96
+ * export default defineConfig({
97
+ * defineConstants: {
98
+ * __TEST__: JSON.stringify('test')
99
+ * }
100
+ * })
101
+ *
102
+ * // src/app.ts
103
+ * onShow() {
104
+ * console.log(__TEST__) // 打印 "test"
105
+ * }
106
+ * ```
107
+ */
34
108
  defineConstants?: IOption
109
+
110
+ /** 用于把文件从源码目录直接拷贝到编译后的生产目录 */
35
111
  copy?: ICopyOptions
112
+
113
+ /** 配置 JS 压缩工具 (默认 terser) */
36
114
  jsMinimizer?: 'terser' | 'esbuild'
115
+
116
+ /** 配置 CSS 压缩工具 (默认 csso) */
37
117
  cssMinimizer?: 'csso' | 'esbuild' | 'parcelCss'
118
+
119
+ /** 配置 csso 工具以压缩 CSS 代码 */
38
120
  csso?: TogglableOptions
121
+
122
+ /** 配置 terser 工具以压缩 JS 代码 */
39
123
  terser?: TogglableOptions
124
+
40
125
  esbuild?: Record<'minify', TogglableOptions>
126
+
41
127
  uglify?: TogglableOptions
128
+
129
+ /** 用于控制对 scss 代码的编译行为,默认使用 dart-sass,具体配置可以参考 https://www.npmjs.com/package/sass */
42
130
  sass?: ISassOptions
131
+
132
+ /** 配置 Taro 插件 */
43
133
  plugins?: PluginItem[]
134
+
135
+ /** 一个 preset 是一系列 Taro 插件的集合,配置语法同 plugins */
44
136
  presets?: PluginItem[]
137
+
138
+ /** 模板循环次数 */
45
139
  baseLevel?: number
46
- framework?: string
140
+
141
+ /** 使用的开发框架。可选值:react、preact、nerv、vue、vue3 */
142
+ framework?: 'react' | 'preact' | 'nerv' | 'vue' | 'vue3'
47
143
  frameworkExts?: string[]
144
+
145
+ /** 使用的编译工具。可选值:webpack4、webpack5 */
48
146
  compiler?: Compiler
147
+
148
+ /** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
49
149
  cache?: ICache
150
+
151
+ /** 控制 Taro 编译日志的输出方式 */
50
152
  logger?: ILogger
153
+
154
+ /** 用于控制是否生成 js、css 对应的 sourceMap */
51
155
  enableSourceMap?: boolean
156
+
52
157
  /**
53
158
  * 编译开始
54
159
  */
55
160
  onBuildStart?: (...args: any[]) => Promise<any>
161
+
56
162
  /**
57
163
  * 编译完成(启动项目后首次编译结束后会触发一次)
58
164
  */
59
165
  onBuildComplete?: (...args: any[]) => Promise<any>
166
+
60
167
  /**
61
168
  * 编译结束(保存代码每次编译结束后都会触发)
62
169
  */
63
- onBuildFinish?: (res: { error, stats, isWatch }) => Promise<any>
170
+ onBuildFinish?: (res: { error; stats; isWatch }) => Promise<any>
171
+
64
172
  /**
65
173
  * 修改编译过程中的页面组件配置
66
174
  */
67
175
  onCompilerMake?: (compilation: Webpack.Compilation, compiler: Webpack.Compiler, plugin: any) => Promise<any>
176
+
68
177
  onWebpackChainReady?: (webpackChain: Chain) => Promise<any>
178
+
69
179
  /**
70
180
  * 编译中修改 webpack 配置,在这个钩子中,你可以对 webpackChain 作出想要的调整,等同于配置 [`webpackChain`](./config-detail#miniwebpackchain)
71
181
  */
72
- modifyWebpackChain?: (chain: Chain, webpack: typeof Webpack, data: IModifyWebpackChain) => Promise<any>
182
+ modifyWebpackChain?: (chain: Chain, webpack: typeof Webpack, data: IModifyChainData) => Promise<any>
183
+
73
184
  /**
74
185
  * 编译中修改 vite 配置
75
186
  */
76
- modifyViteConfig?: (viteConfig: any, componentConfig: IModifyWebpackChain['componentConfig']) => void
187
+ modifyViteConfig?: (viteConfig: any, data: IModifyChainData) => void
188
+
189
+ /**
190
+ * 修改编译后的结果
191
+ */
192
+ modifyBuildAssets?: (assets: any, miniPlugin?: any) => Promise<any>
193
+
77
194
  /**
78
195
  * 修改编译过程中的页面组件配置
79
196
  */
80
- modifyMiniConfigs?: (configMap: any) => Promise<any>
197
+ modifyMiniConfigs?: (configMap: IMiniFilesConfig) => Promise<any>
198
+
81
199
  /**
82
- * 修改编译后的结果
200
+ * 修改 Taro 编译配置
83
201
  */
84
- modifyBuildAssets?: (assets: any, miniPlugin?: any) => Promise<any>
202
+ modifyRunnerOpts?: (opts: any) => Promise<any>
85
203
  }
86
204
 
87
- export interface IProjectConfig extends IProjectBaseConfig {
88
- ui?: {
89
- extraWatchFiles?: any[]
90
- }
91
- mini?: IMiniAppConfig
92
- h5?: IH5Config
93
- rn?: IH5Config
205
+ /** 暴露出来给 config/index 使用的配置类型,参考 https://github.com/NervJS/taro-doctor/blob/main/assets/config_schema.json */
206
+ export interface IProjectConfig<T extends CompilerTypes = CompilerWebpackTypes> {
207
+ /** 项目名称 */
208
+ projectName?: string
209
+
210
+ /** 项目创建日期 */
211
+ date?: string
212
+
213
+ /** 设计稿尺寸 */
214
+ designWidth?: number | ((size?: string | number | Input) => number)
215
+
216
+ /** 设计稿尺寸换算规则 */
217
+ deviceRatio?: TaroGeneral.TDeviceRatio
218
+
219
+ /** 源码存放目录 (默认值:'src') */
220
+ sourceRoot?: string
221
+
222
+ /** 代码编译后的生产目录 (默认值:'dist') */
223
+ outputRoot?: string
224
+
225
+ /**
226
+ * 用于配置`process.env.xxxx`相关的环境变量
227
+ * @deprecated 建议使用根目录下的 .env 文件替代
228
+ * @description 注意:这里的环境变量只能在业务代码中使用,编译时的 node 环境中无法使用
229
+ * @example
230
+ * ```ts
231
+ * // config/index.ts
232
+ * export default defineConfig({
233
+ * env: {
234
+ * xxxx: '"测试"'
235
+ * }
236
+ * })
237
+ *
238
+ * // src/app.ts
239
+ * onShow() {
240
+ * console.log(process.env.xxxx) // 打印 "测试"
241
+ * }
242
+ * ```
243
+ */
244
+ env?: IOption
245
+
246
+ /** 用于配置目录别名,从而方便书写代码引用路径 */
247
+ alias?: IOption
248
+
249
+ /**
250
+ * 用于配置一些常量供代码中进行全局替换使用
251
+ * @description 注意:这里的环境变量只能在业务代码中使用,编译时的 node 环境中无法使用
252
+ * @example
253
+ * ```ts
254
+ * // config/index.ts
255
+ * export default defineConfig({
256
+ * defineConstants: {
257
+ * __TEST__: JSON.stringify('test')
258
+ * }
259
+ * })
260
+ *
261
+ * // src/app.ts
262
+ * onShow() {
263
+ * console.log(__TEST__) // 打印 "test"
264
+ * }
265
+ * ```
266
+ */
267
+ defineConstants?: IOption
268
+
269
+ /** 用于把文件从源码目录直接拷贝到编译后的生产目录 */
270
+ copy?: ICopyOptions
271
+
272
+ /** 配置 JS 压缩工具 (默认 terser) */
273
+ jsMinimizer?: 'terser' | 'esbuild'
274
+
275
+ /** 配置 CSS 压缩工具 (默认 csso) */
276
+ cssMinimizer?: 'csso' | 'esbuild' | 'parcelCss'
277
+
278
+ /** 配置 csso 工具以压缩 CSS 代码 */
279
+ csso?: TogglableOptions
280
+
281
+ /** 配置 terser 工具以压缩 JS 代码 */
282
+ terser?: TogglableOptions
283
+
284
+ esbuild?: Record<'minify', TogglableOptions>
285
+
286
+ /** 用于控制对 scss 代码的编译行为,默认使用 dart-sass,具体配置可以参考 https://www.npmjs.com/package/sass */
287
+ sass?: ISassOptions
288
+
289
+ /** 配置 Taro 插件 */
290
+ plugins?: PluginItem[]
291
+
292
+ /** 一个 preset 是一系列 Taro 插件的集合,配置语法同 plugins */
293
+ presets?: PluginItem[]
294
+
295
+ /** 使用的开发框架。可选值:react、preact、nerv、vue、vue3 */
296
+ framework?: 'react' | 'preact' | 'nerv' | 'vue' | 'vue3'
297
+
298
+ /** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
299
+ cache?: ICache
300
+
301
+ /** 控制 Taro 编译日志的输出方式 */
302
+ logger?: ILogger
303
+
304
+ /** 使用的编译工具。可选值:webpack4、webpack5、vite */
305
+ compiler?: Compiler<T>
306
+
307
+ /** 专属于 H5 的配置 */
308
+ h5?: IH5Config<T>
309
+
310
+ /** 专属于小程序的配置 */
311
+ mini?: IMiniAppConfig<T>
312
+
313
+ /** 专属于 RN 的配置 */
314
+ rn?: IRNConfig
315
+
94
316
  [key: string]: any
95
317
  }
@@ -0,0 +1,64 @@
1
+ import type Webpack from 'webpack'
2
+ import type Chain from 'webpack-chain'
3
+ import type webpackDevServer from 'webpack-dev-server'
4
+ import type HtmlWebpackPlugin from 'html-webpack-plugin'
5
+ import type { IOption, IPostcssOption } from './util'
6
+
7
+ export interface IRNConfig {
8
+ /** 设置 RN bundle 中注册应用的名称 */
9
+ appName?: string
10
+
11
+ /** entry 利用模块查找规则{name}.{platform}.{ext}自动区分平台 */
12
+ entry?: string
13
+
14
+ /** 设置 Metro 打包生成 bundle 的输出路径,默认 dist 目录下 */
15
+ output?: any
16
+
17
+ /** [sass](https://github.com/sass/node-sass#options) 相关配置 */
18
+ sass?: IOption
19
+
20
+ /** [less](https://lesscss.org/usage/#less-options) 相关配置 */
21
+ less?: IOption
22
+
23
+ /** [stylus](https://github.com/NervJS/taro/blob/next/packages/taro-rn-style-transformer/README.md#rnstylus) 相关配置 */
24
+ stylus?: IOption
25
+
26
+ /** 配置 postcss 相关插件 */
27
+ postcss?: {
28
+ /** postcss 配置,参考 https://github.com/postcss/postcss#options */
29
+ options?: any
30
+ /** 默认true,控制是否对 css value 进行 scalePx2dp 转换,pxtransform配置 enable 才生效 */
31
+ scalable?: boolean
32
+ pxtransform?: {
33
+ enable?: boolean
34
+ /** 插件 pxtransform 配置项 */
35
+ config?: {
36
+ additionalProperties?: boolean
37
+ [key: string]: any
38
+ }
39
+ },
40
+ cssModules?: {
41
+ enable: boolean
42
+ },
43
+ [key: string]: any
44
+ }
45
+
46
+ resolve?: any
47
+
48
+ /** 支持多 className 转换,以 classname 或 style 结尾的, 提取前缀, 然后根据前缀,再生成对应的 xxxStyle。如:barClassName -> barStyle。默认值 false,不开启 */
49
+ enableMultipleClassName?: boolean
50
+
51
+ /** 当标签 style 属性值是数组时转换成对象。默认值 false,不开启 */
52
+ enableMergeStyle?: boolean
53
+
54
+ /** 将 svg 文件转换为组件引入。默认值 false,不开启 */
55
+ enableSvgTransform?: boolean
56
+
57
+ alias?: IOption
58
+
59
+ /** 设计稿尺寸 */
60
+ designWidth?: number | ((size?: string | number | Input) => number)
61
+
62
+ /** 设计稿尺寸换算规则 */
63
+ deviceRatio?: TaroGeneral.TDeviceRatio
64
+ }
@@ -1,3 +1,8 @@
1
+ import { type } from 'os'
2
+ import type { Input } from 'postcss'
3
+
4
+ import type { Options as PostcssUrlOption } from 'postcss-url'
5
+
1
6
  export type Func = (...args: any[]) => any
2
7
 
3
8
  export type IOption = Record<string, any>
@@ -7,31 +12,98 @@ export type TogglableOptions<T = IOption> = {
7
12
  config?: T
8
13
  }
9
14
 
15
+ export interface IUrlLoaderOption extends IOption {
16
+ limit?: number | boolean
17
+ name?: ((moduleId: string) => string) | string
18
+ }
19
+
10
20
  export namespace PostcssOption {
11
21
  export type cssModules = TogglableOptions<{
22
+ /** 转换模式,取值为 global/module */
12
23
  namingPattern: 'global' | string
24
+ /** 自定义生成的class名称规则 */
13
25
  generateScopedName: string | ((localName: string, absoluteFilePath: string) => string)
14
26
  }>
15
- export type url = TogglableOptions<{
16
- limit: number
17
- basePath?: string | string[]
18
- }>
27
+ export type url = TogglableOptions<PostcssUrlOption>
19
28
  }
20
29
 
21
- export interface IPostcssOption {
30
+ export interface IHtmlTransformOption {
31
+ /** 是否启用 postcss-html-transform 插件 */
32
+ enable?: boolean
33
+ config?: {
34
+ /** 当前编译平台 (此选项插件内部根据编译平台自行生成,无需传入) */
35
+ readonly platform?: string
36
+ /** 设置是否去除 cursor 相关样式 (h5默认值:true) */
37
+ removeCursorStyle: boolean
38
+ }
39
+ }
40
+
41
+ export interface IPxTransformOption {
42
+ /** 设置 1px 是否需要被转换 */
43
+ onePxTransform?: boolean
44
+ /** REM 单位允许的小数位 */
45
+ unitPrecision?: number
46
+ /** 允许转换的属性列表 (默认 [*]) */
47
+ propList?: string[]
48
+ /** 黑名单里的选择器将会被忽略 */
49
+ selectorBlackList?: Array<string | RegExp>
50
+ /** 直接替换而不是追加一条进行覆盖 */
51
+ replace?: boolean
52
+ /** 允许媒体查询里的 px 单位转换 */
53
+ mediaQuery?: boolean
54
+ /** 设置一个可被转换的最小 px 值 */
55
+ minPixelValue?: number
56
+ /**
57
+ * 转换后的单位,可选值为 rpx、vw、rem,当前仅支持小程序 (默认 rpx) 和 Web 端 (默认 rem)
58
+ * @description Web 端使用 rem 单位时会注入脚本用于设置 body 上的 font-size 属性,其他单位无该操作
59
+ */
60
+ targetUnit?: 'rpx' | 'vw' | 'rem'
61
+ /**
62
+ * H5 字体尺寸大小基准值,开发者可以自行调整单位换算的基准值(默认20)
63
+ * @supported h5
64
+ */
65
+ baseFontSize?: number
66
+ /**
67
+ * H5 根节点 font-size 的最大值 (默认 40)
68
+ * @supported h5
69
+ */
70
+ maxRootSize?: number
71
+ /**
72
+ * H5 根节点 font-size 的最小值(默认 20)
73
+ * @supported h5
74
+ */
75
+ minRootSize?: number
76
+ /** 设计稿尺寸 */
77
+ designWidth?: number | ((size?: string | number | Input) => number)
78
+ /** 设计稿尺寸换算规则 */
79
+ deviceRatio?: TaroGeneral.TDeviceRatio
80
+ /** 平台 */
81
+ platform?: 'weapp' | 'h5' | string
82
+ /** fliter 回调函数,可 exclude 不处理的文件 */
83
+ exclude?: (fileName: string) => boolean
84
+ }
85
+
86
+ interface IBasePostcssOption {
22
87
  autoprefixer?: TogglableOptions
23
- pxtransform?: TogglableOptions
88
+ pxtransform?: TogglableOptions<IPxTransformOption>
24
89
  cssModules?: PostcssOption.cssModules
25
- url?: PostcssOption.url
90
+ /** 插件 postcss-html-transform 相关配置, 一般启用了 @tarojs/plugin-html 插件才配置 */
91
+ htmltransform?: IHtmlTransformOption
26
92
  [key: string]: any
27
93
  }
28
94
 
95
+ export type IPostcssOption<T = 'H5' | 'mini'> = T extends 'H5'
96
+ ? IBasePostcssOption & { url?: PostcssOption.url }
97
+ : IBasePostcssOption
98
+
99
+ export type Conifg = ViteConfg | WebpackConfig
100
+
29
101
  export interface ICopyOptions {
30
102
  patterns: {
31
103
  from: string
32
104
  to: string
33
105
  ignore?: string[]
34
- transform?: Function
106
+ transform?: Func
35
107
  watch?: boolean
36
108
  }[]
37
109
  options: {
@@ -96,9 +168,9 @@ export const enum CONFIG_TYPES {
96
168
  }
97
169
 
98
170
  export type IMINI_APP_FILE_TYPE = {
99
- TEMPL: TEMPLATE_TYPES,
100
- STYLE: STYLE_TYPES,
101
- SCRIPT: SCRIPT_TYPES,
171
+ TEMPL: TEMPLATE_TYPES
172
+ STYLE: STYLE_TYPES
173
+ SCRIPT: SCRIPT_TYPES
102
174
  CONFIG: CONFIG_TYPES
103
175
  }
104
176
 
@@ -8,6 +8,6 @@ export interface IComponentConfig {
8
8
  includeAll: boolean
9
9
  }
10
10
 
11
- export interface IModifyWebpackChain {
11
+ export interface IModifyChainData {
12
12
  componentConfig?: IComponentConfig
13
13
  }