@tarojs/taro 3.8.0-canary.0 → 4.0.0-alpha.2

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 (101) hide show
  1. package/html.css +9 -0
  2. package/package.json +16 -4
  3. package/types/api/ad/index.d.ts +6 -18
  4. package/types/api/ai/inference.d.ts +4 -8
  5. package/types/api/ai/visionkit.d.ts +625 -54
  6. package/types/api/base/debug.d.ts +8 -8
  7. package/types/api/base/env.d.ts +1 -1
  8. package/types/api/base/index.d.ts +3 -3
  9. package/types/api/base/performance.d.ts +5 -5
  10. package/types/api/base/system.d.ts +6 -6
  11. package/types/api/base/weapp/app-event.d.ts +10 -10
  12. package/types/api/base/weapp/life-cycle.d.ts +1 -1
  13. package/types/api/canvas/index.d.ts +389 -72
  14. package/types/api/data-analysis/index.d.ts +51 -1
  15. package/types/api/device/accelerometer.d.ts +8 -6
  16. package/types/api/device/accessibility.d.ts +1 -1
  17. package/types/api/device/battery.d.ts +3 -3
  18. package/types/api/device/bluetooth-ble.d.ts +40 -17
  19. package/types/api/device/bluetooth-peripheral.d.ts +26 -26
  20. package/types/api/device/bluetooth.d.ts +37 -13
  21. package/types/api/device/calendar.d.ts +11 -1
  22. package/types/api/device/clipboard.d.ts +17 -17
  23. package/types/api/device/compass.d.ts +5 -5
  24. package/types/api/device/gyroscope.d.ts +4 -4
  25. package/types/api/device/iBeacon.d.ts +10 -8
  26. package/types/api/device/keyboard.d.ts +7 -5
  27. package/types/api/device/memory.d.ts +3 -4
  28. package/types/api/device/motion.d.ts +8 -6
  29. package/types/api/device/network.d.ts +12 -6
  30. package/types/api/device/nfc.d.ts +13 -13
  31. package/types/api/device/phone.d.ts +1 -1
  32. package/types/api/device/scan.d.ts +5 -3
  33. package/types/api/device/screen.d.ts +28 -12
  34. package/types/api/device/sms.d.ts +1 -1
  35. package/types/api/device/vibrate.d.ts +5 -5
  36. package/types/api/device/wifi.d.ts +25 -13
  37. package/types/api/files/index.d.ts +73 -43
  38. package/types/api/framework/index.d.ts +2 -2
  39. package/types/api/location/index.d.ts +167 -19
  40. package/types/api/media/audio.d.ts +71 -42
  41. package/types/api/media/background-audio.d.ts +1 -1
  42. package/types/api/media/camera.d.ts +6 -3
  43. package/types/api/media/image.d.ts +5 -5
  44. package/types/api/media/video.d.ts +11 -11
  45. package/types/api/navigate/index.d.ts +3 -1
  46. package/types/api/network/download.d.ts +7 -15
  47. package/types/api/network/request.d.ts +7 -7
  48. package/types/api/network/upload.d.ts +9 -17
  49. package/types/api/network/websocket.d.ts +8 -8
  50. package/types/api/open-api/account.d.ts +1 -1
  51. package/types/api/open-api/address.d.ts +13 -5
  52. package/types/api/open-api/authorize.d.ts +1 -1
  53. package/types/api/open-api/channels.d.ts +16 -0
  54. package/types/api/open-api/device-voip.d.ts +42 -2
  55. package/types/api/open-api/invoice.d.ts +1 -1
  56. package/types/api/open-api/login.d.ts +16 -3
  57. package/types/api/open-api/my-miniprogram.d.ts +2 -2
  58. package/types/api/open-api/privacy.d.ts +107 -0
  59. package/types/api/open-api/settings.d.ts +3 -2
  60. package/types/api/open-api/sticker.d.ts +83 -0
  61. package/types/api/open-api/subscribe-message.d.ts +148 -6
  62. package/types/api/open-api/user-info.d.ts +6 -1
  63. package/types/api/qq/index.d.ts +306 -1
  64. package/types/api/route/index.d.ts +8 -5
  65. package/types/api/skyline/index.d.ts +59 -0
  66. package/types/api/storage/background-fetch.d.ts +63 -11
  67. package/types/api/storage/cache-manager.d.ts +61 -10
  68. package/types/api/storage/index.d.ts +125 -10
  69. package/types/api/swan/bookshelf.d.ts +307 -0
  70. package/types/api/swan/download-package.d.ts +80 -0
  71. package/types/api/swan/index.d.ts +151 -0
  72. package/types/api/swan/pay.d.ts +139 -0
  73. package/types/api/taro.extend.d.ts +15 -6
  74. package/types/api/taro.hooks.d.ts +9 -9
  75. package/types/api/ui/animation.d.ts +32 -32
  76. package/types/api/ui/custom-component.d.ts +1 -1
  77. package/types/api/ui/fonts.d.ts +4 -3
  78. package/types/api/ui/interaction.d.ts +6 -6
  79. package/types/api/ui/menu.d.ts +1 -1
  80. package/types/api/ui/navigation-bar.d.ts +5 -5
  81. package/types/api/ui/pull-down-refresh.d.ts +2 -2
  82. package/types/api/ui/scroll.d.ts +1 -1
  83. package/types/api/ui/tab-bar.d.ts +8 -8
  84. package/types/api/ui/window.d.ts +2 -2
  85. package/types/api/wxml/index.d.ts +19 -19
  86. package/types/compile/compiler.d.ts +9 -4
  87. package/types/compile/config/h5.d.ts +23 -10
  88. package/types/compile/config/harmony.d.ts +82 -0
  89. package/types/compile/config/index.d.ts +1 -0
  90. package/types/compile/config/mini.d.ts +58 -30
  91. package/types/compile/config/plugin.d.ts +34 -0
  92. package/types/compile/config/project.d.ts +26 -13
  93. package/types/compile/config/util.d.ts +22 -8
  94. package/types/compile/viteCompilerContext.d.ts +155 -0
  95. package/types/global.d.ts +3 -1
  96. package/types/index.d.ts +92 -44
  97. package/types/taro.api.d.ts +24 -13
  98. package/types/taro.component.d.ts +2 -1
  99. package/types/taro.config.d.ts +47 -6
  100. package/types/taro.lifecycle.d.ts +3 -0
  101. package/types/taro.runtime.d.ts +9 -0
@@ -18,12 +18,12 @@ declare module '../../index' {
18
18
  */
19
19
  interface IntersectionObserver {
20
20
  /** 停止监听。回调函数将不再触发
21
- * @supported weapp, tt, h5
21
+ * @supported weapp, tt, h5, harmony_hybrid
22
22
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/IntersectionObserver.disconnect.html
23
23
  */
24
24
  disconnect(): void
25
25
  /** 指定目标节点并开始监听相交状态变化情况
26
- * @supported weapp, tt, h5
26
+ * @supported weapp, tt, h5, harmony_hybrid
27
27
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/IntersectionObserver.observe.html
28
28
  */
29
29
  observe(
@@ -33,7 +33,7 @@ declare module '../../index' {
33
33
  callback: IntersectionObserver.ObserveCallback,
34
34
  ): void
35
35
  /** 使用选择器指定一个节点,作为参照区域之一。
36
- * @supported weapp, tt, h5
36
+ * @supported weapp, tt, h5, harmony_hybrid
37
37
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/IntersectionObserver.relativeTo.html
38
38
  */
39
39
  relativeTo(
@@ -43,7 +43,7 @@ declare module '../../index' {
43
43
  margins?: IntersectionObserver.RelativeToMargins,
44
44
  ): IntersectionObserver
45
45
  /** 指定页面显示区域作为参照区域之一
46
- * @supported weapp, tt, h5
46
+ * @supported weapp, tt, h5, harmony_hybrid
47
47
  * @example
48
48
  * 下面的示例代码中,如果目标节点(用选择器 .target-class 指定)进入显示区域以下 100px 时,就会触发回调函数。
49
49
  *
@@ -184,7 +184,7 @@ declare module '../../index' {
184
184
  */
185
185
  interface NodesRef {
186
186
  /** 添加节点的布局位置的查询请求。相对于显示区域,以像素为单位。其功能类似于 DOM 的 `getBoundingClientRect`。返回 `NodesRef` 对应的 `SelectorQuery`。
187
- * @supported weapp, h5, tt
187
+ * @supported weapp, h5, tt, harmony_hybrid
188
188
  * @example
189
189
  * ```tsx
190
190
  * Taro.createSelectorQuery().select('#the-id').boundingClientRect(function(rect){
@@ -220,7 +220,7 @@ declare module '../../index' {
220
220
  callback?: NodesRef.BoundingClientRectCallback,
221
221
  ): SelectorQuery
222
222
  /** 添加节点的 Context 对象查询请求。目前支持 [VideoContext](/docs/apis/media/video/VideoContext)、[CanvasContext](/docs/apis/canvas/CanvasContext)、[LivePlayerContext](/docs/apis/media/live/LivePlayerContext)、[EditorContext](/docs/apis/media/editor/EditorContext)和 [MapContext](/docs/apis/media/map/MapContext) 的获取。
223
- * @supported weapp, h5, tt
223
+ * @supported weapp, h5, tt, harmony_hybrid
224
224
  * @example
225
225
  * ```tsx
226
226
  * Taro.createSelectorQuery().select('.the-video-class').context(function (res) {
@@ -237,7 +237,7 @@ declare module '../../index' {
237
237
  *
238
238
  * **注意**
239
239
  * computedStyle 的优先级高于 size,当同时在 computedStyle 里指定了 width/height 和传入了 size: true,则优先返回 computedStyle 获取到的 width/height。
240
- * @supported weapp, h5, tt
240
+ * @supported weapp, h5, tt, harmony_hybrid
241
241
  * @example
242
242
  * ```tsx
243
243
  * Taro.createSelectorQuery().select('#the-id').fields({
@@ -269,7 +269,7 @@ declare module '../../index' {
269
269
  callback?: NodesRef.FieldsCallback,
270
270
  ): SelectorQuery
271
271
  /** 获取 Node 节点实例。目前支持 [Canvas](/docs/components/canvas) 的获取。
272
- * @supported weapp, h5, tt
272
+ * @supported weapp, h5, tt, harmony_hybrid
273
273
  * @example
274
274
  * ```tsx
275
275
  * Taro.createSelectorQuery().select('.canvas').node(function(res){
@@ -283,7 +283,7 @@ declare module '../../index' {
283
283
  callback?: NodesRef.NodeCallback,
284
284
  ): SelectorQuery
285
285
  /** 添加节点的滚动位置查询请求。以像素为单位。节点必须是 `scroll-view` 或者 `viewport`,返回 `NodesRef` 对应的 `SelectorQuery`。
286
- * @supported weapp, h5, tt
286
+ * @supported weapp, h5, tt, harmony_hybrid
287
287
  * @example
288
288
  * ```tsx
289
289
  * Taro.createSelectorQuery().selectViewport().scrollOffset(function(res){
@@ -384,7 +384,7 @@ declare module '../../index' {
384
384
  */
385
385
  interface SelectorQuery {
386
386
  /** 执行所有的请求。请求结果按请求次序构成数组,在callback的第一个参数中返回。
387
- * @supported weapp, h5, tt
387
+ * @supported weapp, h5, tt, harmony_hybrid
388
388
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/SelectorQuery.exec.html
389
389
  */
390
390
  exec(
@@ -392,7 +392,7 @@ declare module '../../index' {
392
392
  callback?: (...args: any[]) => any,
393
393
  ): NodesRef
394
394
  /** 将选择器的选取范围更改为自定义组件 `component` 内。(初始时,选择器仅选取页面范围的节点,不会选取任何自定义组件中的节点)。
395
- * @supported weapp, h5, tt
395
+ * @supported weapp, h5, tt, harmony_hybrid
396
396
  * @example
397
397
  * ```tsx
398
398
  * Component({
@@ -423,7 +423,7 @@ declare module '../../index' {
423
423
  * - 后代选择器:.the-ancestor .the-descendant
424
424
  * - 跨自定义组件的后代选择器:.the-ancestor >>> .the-descendant
425
425
  * - 多选择器的并集:#a-node, .some-other-nodes
426
- * @supported weapp, h5, tt
426
+ * @supported weapp, h5, tt, harmony_hybrid
427
427
  * @example
428
428
  * ```tsx
429
429
  * Taro.createSelectorQuery().select('#the-id').fields({
@@ -459,7 +459,7 @@ declare module '../../index' {
459
459
  * - 后代选择器:.the-ancestor .the-descendant
460
460
  * - 跨自定义组件的后代选择器:.the-ancestor >>> .the-descendant
461
461
  * - 多选择器的并集:#a-node, .some-other-nodes
462
- * @supported weapp, h5, tt
462
+ * @supported weapp, h5, tt, harmony_hybrid
463
463
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/SelectorQuery.selectAll.html
464
464
  */
465
465
  selectAll(
@@ -467,7 +467,7 @@ declare module '../../index' {
467
467
  selector: string,
468
468
  ): NodesRef
469
469
  /** 选择显示区域。可用于获取显示区域的尺寸、滚动位置等信息。
470
- * @supported weapp, h5, tt
470
+ * @supported weapp, h5, tt, harmony_hybrid
471
471
  * @example
472
472
  * ```tsx
473
473
  * Taro.createSelectorQuery().selectViewport().scrollOffset(function (res) {
@@ -484,7 +484,7 @@ declare module '../../index' {
484
484
 
485
485
  interface TaroStatic {
486
486
  /** 返回一个 SelectorQuery 对象实例。在自定义组件或包含自定义组件的页面中,应使用 `this.createSelectorQuery()` 来代替。
487
- * @supported weapp, h5, tt
487
+ * @supported weapp, h5, tt, harmony, harmony_hybrid
488
488
  * @example
489
489
  * ```tsx
490
490
  * const query = Taro.createSelectorQuery()
@@ -500,10 +500,10 @@ declare module '../../index' {
500
500
  createSelectorQuery(): SelectorQuery
501
501
 
502
502
  /** 创建并返回一个 IntersectionObserver 对象实例。在自定义组件或包含自定义组件的页面中,应使用 `this.createIntersectionObserver([options])` 来代替。
503
- * @supported weapp, h5, tt
503
+ * @supported weapp, h5, tt, harmony, harmony_hybrid
504
504
  * @example
505
505
  * ```tsx
506
- * const observer = Taro.createIntersectionObserver(this, { thresholds: [0], observeAll: true })
506
+ * const observer = Taro.createIntersectionObserver(this, { thresholds: [0], observeAll: true })
507
507
  * ```
508
508
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/wxml/wx.createIntersectionObserver.html
509
509
  */
@@ -515,7 +515,7 @@ declare module '../../index' {
515
515
  ): IntersectionObserver
516
516
 
517
517
  /** 创建并返回一个 MediaQueryObserver 对象实例。在自定义组件或包含自定义组件的页面中,应使用 `this.createMediaQueryObserver()` 来代替。
518
- * @supported h5
518
+ * @supported h5, harmony_hybrid
519
519
  * @example
520
520
  * ```tsx
521
521
  * let createMediaQueryObserver
@@ -525,7 +525,7 @@ declare module '../../index' {
525
525
  * } else if (process.env.TARO_ENV === 'h5') {
526
526
  * createMediaQueryObserver= Taro.createMediaQueryObserver
527
527
  * }
528
- * const mediaQueryObserver = createMediaQueryObserver()
528
+ * const mediaQueryObserver = createMediaQueryObserver()
529
529
  * ```
530
530
  * @see https://developers.weixin.qq.com/miniprogram/dev/framework/view/resizable.html#Media%20Query
531
531
  */
@@ -1,7 +1,9 @@
1
1
  import type { swc } from '@tarojs/helper'
2
2
  import type Webpack from 'webpack'
3
3
 
4
- type CompilerTypes = 'webpack4' | 'webpack5'
4
+ export type CompilerTypes = CompilerWebpackTypes | 'vite'
5
+
6
+ export type CompilerWebpackTypes = 'webpack5' | 'webpack4'
5
7
 
6
8
  interface IPrebundle {
7
9
  enable?: boolean
@@ -17,9 +19,12 @@ interface IPrebundle {
17
19
  }
18
20
  }
19
21
 
20
- interface ICompiler {
21
- type: CompilerTypes
22
+ interface ICompiler<T> {
23
+ type: T
22
24
  prebundle?: IPrebundle
25
+ vitePlugins?: any
26
+ /** 错误处理级别。可选值:0、1 */
27
+ errorLevel?: number
23
28
  }
24
29
 
25
- export type Compiler = CompilerTypes | ICompiler
30
+ export type Compiler<T extends CompilerTypes = CompilerWebpackTypes> = T | ICompiler<T>
@@ -2,7 +2,9 @@ import type Webpack from 'webpack'
2
2
  import type Chain from 'webpack-chain'
3
3
  import type webpackDevServer from 'webpack-dev-server'
4
4
  import type HtmlWebpackPlugin from 'html-webpack-plugin'
5
- import type { IOption, IPostcssOption } from './util'
5
+ import type { IOption, IPostcssOption, IUrlLoaderOption } from './util'
6
+ import type { OutputOptions as RollupOutputOptions } from 'rollup'
7
+ import type { Compiler, CompilerTypes, CompilerWebpackTypes } from '../compiler'
6
8
 
7
9
  export interface IH5RouterConfig {
8
10
  /** 配置路由模式 */
@@ -16,7 +18,7 @@ export interface IH5RouterConfig {
16
18
  forcePath?: string
17
19
  }
18
20
 
19
- export interface IH5Config {
21
+ export interface IH5Config <T extends CompilerTypes = CompilerWebpackTypes> {
20
22
  /** 设置输出解析文件的目录(默认值:'/')*/
21
23
  publicPath?: string
22
24
 
@@ -35,8 +37,10 @@ export interface IH5Config {
35
37
  */
36
38
  webpackChain?: (chain: Chain, webpack: typeof Webpack) => void
37
39
 
38
- /** 可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/) */
39
- output?: Webpack.Configuration['output']
40
+ /** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/)
41
+ * vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/)
42
+ */
43
+ output?: T extends 'vite' ? Pick<RollupOutputOptions, 'chunkFileNames' | 'assetFileNames' > : Webpack.Configuration['output']
40
44
 
41
45
  /** 路由相关的配置 */
42
46
  router?: IH5RouterConfig
@@ -44,6 +48,9 @@ export interface IH5Config {
44
48
  /** 预览服务的配置,可以更改端口等参数。具体配置参考 [webpack-dev-server](https://webpack.js.org/configuration/dev-server) */
45
49
  devServer?: webpackDevServer.Configuration
46
50
 
51
+ /** 用于控制是否生成 js、css 对应的 sourceMap (默认值:watch 模式下为 true,否则为 false) */
52
+ enableSourceMap?: boolean
53
+
47
54
  /** 具体配置请参考 [Webpack devtool](https://webpack.js.org/configuration/devtool/#devtool) 配置 (默认值:'cheap-module-eval-source-map')*/
48
55
  sourceMapType?:
49
56
  | 'none'
@@ -79,13 +86,13 @@ export interface IH5Config {
79
86
  stylusLoaderOption?: IOption
80
87
 
81
88
  /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
82
- mediaUrlLoaderOption?: IOption
89
+ mediaUrlLoaderOption?: IUrlLoaderOption
83
90
 
84
91
  /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
85
- fontUrlLoaderOption?: IOption
92
+ fontUrlLoaderOption?: IUrlLoaderOption
86
93
 
87
94
  /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
88
- imageUrlLoaderOption?: IOption
95
+ imageUrlLoaderOption?: IUrlLoaderOption
89
96
 
90
97
  /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
91
98
  miniCssExtractPluginOption?: IOption
@@ -100,14 +107,20 @@ export interface IH5Config {
100
107
  useDeprecatedAdapterComponent?: boolean
101
108
 
102
109
  /** 配置 postcss 相关插件 */
103
- postcss?: IPostcssOption
110
+ postcss?: IPostcssOption<'h5'>
104
111
 
105
112
  /** html-webpack-plugin 的具体配置 */
106
113
  htmlPluginOption?: HtmlWebpackPlugin.Options
107
114
 
108
115
  /** Web 编译过程的相关配置 */
109
116
  compile?: {
110
- exclude?: any[]
111
- include?: any[]
117
+ exclude?: (string | RegExp)[]
118
+ include?: (string | RegExp)[]
119
+ filter?: (filename: string) => boolean
112
120
  }
121
+ /** 生成的代码是否要兼容旧版浏览器,值为 true 时,会去读取 package.json 的 browserslist 字段。只在 vite 编译模式下有效 */
122
+ legacy?: T extends 'vite' ? boolean : undefined
123
+
124
+ /** 使用的编译工具。可选值:webpack4、webpack5、vite */
125
+ compiler?: Compiler<T>
113
126
  }
@@ -0,0 +1,82 @@
1
+ import type Chain from 'webpack-chain'
2
+
3
+ import type { IOption, IPostcssOption, IUrlLoaderOption } from './util'
4
+ import type { Compiler, CompilerTypes, CompilerWebpackTypes } from '../compiler'
5
+
6
+ export interface IHarmonyConfig<T extends CompilerTypes = CompilerWebpackTypes> {
7
+ /** Harmony 编译方式 */
8
+ compiler?: Compiler
9
+
10
+ /** Harmony 项目地址 */
11
+ projectPath: string
12
+
13
+ /** hap 名
14
+ * @default "entry"
15
+ */
16
+ hapName?: string
17
+
18
+ /** 应用名称
19
+ * @default "default"
20
+ */
21
+ name?: string
22
+
23
+ /** 用于告诉 Taro 编译器需要抽取的公共文件 */
24
+ commonChunks?: string[] | ((commonChunks: string[]) => string[])
25
+
26
+ /** Harmony 编译过程的相关配置 */
27
+ compile?: {
28
+ exclude?: any[]
29
+ include?: any[]
30
+ filter?: (filename: string) => boolean
31
+ }
32
+
33
+ /** 用于控制是否生成 js、css 对应的 sourceMap (默认值:watch 模式下为 true,否则为 false) */
34
+ enableSourceMap?: boolean
35
+
36
+ /** 默认值:'cheap-module-source-map', 具体参考[Webpack devtool 配置](https://webpack.js.org/configuration/devtool/#devtool) */
37
+ sourceMapType?: string
38
+
39
+ /** 指定 React 框架相关的代码是否使用开发环境(未压缩)代码,默认使用生产环境(压缩后)代码 */
40
+ debugReact?: boolean
41
+
42
+ /**
43
+ * 自定义 Webpack 配置
44
+ * @param chain [webpackChain](https://github.com/neutrinojs/webpack-chain) 对象
45
+ * @param webpack webpack 实例
46
+ */
47
+ webpackChain?: (chain: Chain, webpack: typeof Webpack) => void
48
+
49
+ /** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/)
50
+ * vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/)
51
+ */
52
+ output?: T extends 'vite'
53
+ ? Pick<RollupOutputOptions, 'chunkFileNames'> & OutputExt
54
+ : Webpack.Configuration['output'] & OutputExt
55
+
56
+ /** 配置 postcss 相关插件 */
57
+ postcss?: IPostcssOption<'harmony'>
58
+
59
+ /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
60
+ cssLoaderOption?: IOption
61
+
62
+ /** [sass-loader](https://github.com/webpack-contrib/sass-loader) 的附加配置 */
63
+ sassLoaderOption?: IOption
64
+
65
+ /** [less-loader](https://github.com/webpack-contrib/less-loader) 的附加配置 */
66
+ lessLoaderOption?: IOption
67
+
68
+ /** [stylus-loader](https://github.com/shama/stylus-loader) 的附加配置 */
69
+ stylusLoaderOption?: IOption
70
+
71
+ /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
72
+ mediaUrlLoaderOption?: IUrlLoaderOption
73
+
74
+ /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
75
+ fontUrlLoaderOption?: IUrlLoaderOption
76
+
77
+ /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
78
+ imageUrlLoaderOption?: IUrlLoaderOption
79
+
80
+ /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
81
+ miniCssExtractPluginOption?: IOption
82
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './h5'
2
+ export * from './harmony'
2
3
  export * from './mini'
3
4
 
4
5
  export * from './manifest'
@@ -1,18 +1,38 @@
1
1
  import type Webpack from 'webpack'
2
2
  import type Chain from 'webpack-chain'
3
- import type { IOption, IPostcssOption } from './util'
3
+ import type { IOption, IPostcssOption, IUrlLoaderOption } from './util'
4
+ import type { OutputOptions as RollupOutputOptions } from 'rollup'
5
+ import type { Compiler, CompilerTypes, CompilerWebpackTypes } from '../compiler'
4
6
 
5
7
  interface Runtime {
6
- enableInnerHTML: boolean
7
- enableSizeAPIs: boolean
8
- enableAdjacentHTML: boolean
9
- enableTemplateContent: boolean
10
- enableCloneNode: boolean
11
- enableContains: boolean
12
- enableMutationObserver: boolean
8
+ enableInnerHTML?: boolean
9
+ enableSizeAPIs?: boolean
10
+ enableAdjacentHTML?: boolean
11
+ enableTemplateContent?: boolean
12
+ enableCloneNode?: boolean
13
+ enableContains?: boolean
14
+ enableMutationObserver?: boolean
13
15
  }
14
16
 
15
- export interface IMiniAppConfig {
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
+ /** 用于控制是否生成 js、css 对应的 sourceMap (默认值:watch 模式下为 true,否则为 false) */
34
+ enableSourceMap?: boolean
35
+
16
36
  /** 默认值:'cheap-module-source-map', 具体参考[Webpack devtool 配置](https://webpack.js.org/configuration/devtool/#devtool) */
17
37
  sourceMapType?: string
18
38
 
@@ -37,24 +57,15 @@ export interface IMiniAppConfig {
37
57
  */
38
58
  webpackChain?: (chain: Chain, webpack: typeof Webpack, PARSE_AST_TYPE: any) => void
39
59
 
40
- /** 可用于修改、拓展 Webpack 的 [output](https://webpack.js.org/configuration/output/) 选项 */
41
- output?: Webpack.Configuration['output'] & {
42
- /**
43
- * 编译前清空输出目录
44
- * @since Taro v3.6.9
45
- * @description
46
- * - 默认清空输出目录,可设置 clean: false 不清空
47
- * - 可设置 clean: { keep: ['project.config.json'] } 保留指定文件
48
- * - 注意 clean.keep 不支持函数
49
- */
50
- clean?: boolean | {
51
- /** 保留指定文件不删除 */
52
- keep?: Array<string | RegExp> | string | RegExp
53
- }
54
- }
60
+ /** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/)
61
+ * vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/)
62
+ */
63
+ output?: T extends 'vite'
64
+ ? Pick<RollupOutputOptions, 'chunkFileNames'> & OutputExt
65
+ : Webpack.Configuration['output'] & OutputExt
55
66
 
56
67
  /** 配置 postcss 相关插件 */
57
- postcss?: IPostcssOption
68
+ postcss?: IPostcssOption<'mini'>
58
69
 
59
70
  /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
60
71
  cssLoaderOption?: IOption
@@ -69,13 +80,13 @@ export interface IMiniAppConfig {
69
80
  stylusLoaderOption?: IOption
70
81
 
71
82
  /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
72
- mediaUrlLoaderOption?: IOption
83
+ mediaUrlLoaderOption?: IUrlLoaderOption
73
84
 
74
85
  /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
75
- fontUrlLoaderOption?: IOption
86
+ fontUrlLoaderOption?: IUrlLoaderOption
76
87
 
77
88
  /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
78
- imageUrlLoaderOption?: IOption
89
+ imageUrlLoaderOption?: IUrlLoaderOption
79
90
 
80
91
  /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
81
92
  miniCssExtractPluginOption?: IOption
@@ -94,10 +105,27 @@ export interface IMiniAppConfig {
94
105
 
95
106
  /** 小程序编译过程的相关配置 */
96
107
  compile?: {
97
- exclude?: any[]
98
- include?: any[]
108
+ exclude?: (string | RegExp)[]
109
+ include?: (string | RegExp)[]
110
+ filter?: (filename: string) => boolean
99
111
  }
100
112
 
101
113
  /** 插件内部使用 */
102
114
  runtime?: Runtime
115
+
116
+ /** 使用的编译工具。可选值:webpack4、webpack5、vite */
117
+ compiler?: Compiler<T>
118
+
119
+ /** 体验式功能 */
120
+ experimental?: {
121
+ /** 是否开启编译模式 */
122
+ compileMode?: boolean | string
123
+ }
124
+ }
125
+
126
+ export interface IMiniFilesConfig {
127
+ [configName: string]: {
128
+ content: any
129
+ path: string
130
+ }
103
131
  }
@@ -0,0 +1,34 @@
1
+ import type { CustomPluginOptions, ResolvedId, ResolveIdResult } from 'rollup'
2
+
3
+ interface IRollupPluginResolveIdOptions {
4
+ assertions?: Record<string, string>
5
+ custom?: CustomPluginOptions
6
+ isEntry?: boolean
7
+ skipSelf?: boolean
8
+ }
9
+
10
+ export type TRollupResolveMethod = (
11
+ source: string,
12
+ importer?: string,
13
+ options?: IRollupPluginResolveIdOptions
14
+ ) => Promise<ResolvedId | null>
15
+
16
+ export interface ILoaderMeta {
17
+ importFrameworkStatement: string
18
+ importFrameworkName: string
19
+ creator: string
20
+ creatorLocation: string
21
+ extraImportForWeb: string
22
+ execBeforeCreateWebApp: string
23
+ frameworkArgs: string
24
+ isNeedRawLoader?: boolean
25
+ mockAppStatement: string
26
+ modifyConfig?: (config: Record<string, any>, source: string) => void
27
+ modifyResolveId?: (res: {
28
+ source?: string
29
+ importer?: string
30
+ options?: IRollupPluginResolveIdOptions
31
+ name?: string
32
+ resolve: TRollupResolveMethod
33
+ }) => Promise<ResolveIdResult> | ResolveIdResult
34
+ }
@@ -1,12 +1,13 @@
1
1
  import type Webpack from 'webpack'
2
2
  import type Chain from 'webpack-chain'
3
- import { type Input } from 'postcss'
4
- import type { Compiler } from '../compiler'
3
+ import type { Input } from 'postcss'
4
+ import type { Compiler, CompilerTypes, CompilerWebpackTypes } from '../compiler'
5
5
  import type { IModifyChainData } from '../hooks'
6
6
  import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from './util'
7
7
  import type { IH5Config } from './h5'
8
- import type { IMiniAppConfig } from './mini'
9
- import { IRNConfig } from './rn'
8
+ import type { IHarmonyConfig } from './harmony'
9
+ import type { IMiniAppConfig, IMiniFilesConfig } from './mini'
10
+ import type { IRNConfig } from './rn'
10
11
 
11
12
  export type PluginItem<T = object> = string | [string, T] | [string, () => T | Promise<T>]
12
13
 
@@ -182,18 +183,28 @@ export interface IProjectBaseConfig {
182
183
  modifyWebpackChain?: (chain: Chain, webpack: typeof Webpack, data: IModifyChainData) => Promise<any>
183
184
 
184
185
  /**
185
- * 修改编译过程中的页面组件配置
186
+ * 编译中修改 vite 配置
186
187
  */
187
- modifyMiniConfigs?: (configMap: any) => Promise<any>
188
+ modifyViteConfig?: (viteConfig: any, data: IModifyChainData) => void
188
189
 
189
190
  /**
190
191
  * 修改编译后的结果
191
192
  */
192
193
  modifyBuildAssets?: (assets: any, miniPlugin?: any) => Promise<any>
194
+
195
+ /**
196
+ * 修改编译过程中的页面组件配置
197
+ */
198
+ modifyMiniConfigs?: (configMap: IMiniFilesConfig) => Promise<any>
199
+
200
+ /**
201
+ * 修改 Taro 编译配置
202
+ */
203
+ modifyRunnerOpts?: (opts: any) => Promise<any>
193
204
  }
194
205
 
195
206
  /** 暴露出来给 config/index 使用的配置类型,参考 https://github.com/NervJS/taro-doctor/blob/main/assets/config_schema.json */
196
- export interface IProjectConfig {
207
+ export interface IProjectConfig<T extends CompilerTypes = CompilerWebpackTypes> {
197
208
  /** 项目名称 */
198
209
  projectName?: string
199
210
 
@@ -285,23 +296,25 @@ export interface IProjectConfig {
285
296
  /** 使用的开发框架。可选值:react、preact、nerv、vue、vue3 */
286
297
  framework?: 'react' | 'preact' | 'nerv' | 'vue' | 'vue3'
287
298
 
288
- /** 使用的编译工具。可选值:webpack4、webpack5 */
289
- compiler?: Compiler
290
-
291
299
  /** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
292
300
  cache?: ICache
293
301
 
294
302
  /** 控制 Taro 编译日志的输出方式 */
295
303
  logger?: ILogger
296
304
 
297
- /** 专属于小程序的配置 */
298
- mini?: IMiniAppConfig
305
+ /** 使用的编译工具。可选值:webpack4、webpack5、vite */
306
+ compiler?: Compiler<T>
299
307
 
300
308
  /** 专属于 H5 的配置 */
301
- h5?: IH5Config
309
+ h5?: IH5Config<T>
310
+
311
+ /** 专属于小程序的配置 */
312
+ mini?: IMiniAppConfig<T>
302
313
 
303
314
  /** 专属于 RN 的配置 */
304
315
  rn?: IRNConfig
305
316
 
317
+ harmony?: IHarmonyConfig<T>
318
+
306
319
  [key: string]: any
307
320
  }
@@ -1,4 +1,5 @@
1
- import { type Input } from 'postcss'
1
+ import type { Input } from 'postcss'
2
+ import type { Options as PostcssUrlOption } from 'postcss-url'
2
3
 
3
4
  export type Func = (...args: any[]) => any
4
5
 
@@ -9,6 +10,11 @@ export type TogglableOptions<T = IOption> = {
9
10
  config?: T
10
11
  }
11
12
 
13
+ export interface IUrlLoaderOption extends IOption {
14
+ limit?: number | boolean
15
+ name?: ((moduleId: string) => string) | string
16
+ }
17
+
12
18
  export namespace PostcssOption {
13
19
  export type cssModules = TogglableOptions<{
14
20
  /** 转换模式,取值为 global/module */
@@ -16,10 +22,7 @@ export namespace PostcssOption {
16
22
  /** 自定义生成的class名称规则 */
17
23
  generateScopedName: string | ((localName: string, absoluteFilePath: string) => string)
18
24
  }>
19
- export type url = TogglableOptions<{
20
- limit: number
21
- basePath?: string | string[]
22
- }>
25
+ export type url = TogglableOptions<PostcssUrlOption>
23
26
  }
24
27
 
25
28
  export interface IHtmlTransformOption {
@@ -72,24 +75,35 @@ export interface IPxTransformOption {
72
75
  designWidth?: number | ((size?: string | number | Input) => number)
73
76
  /** 设计稿尺寸换算规则 */
74
77
  deviceRatio?: TaroGeneral.TDeviceRatio
78
+ /** 平台 */
79
+ platform?: 'weapp' | 'h5' | string
80
+ /** 启用的能力 Scope 默认为 ['platform', 'size'] */
81
+ methods?: string[]
82
+ /** filter 回调函数,可 exclude 不处理的文件 */
83
+ exclude?: (fileName: string) => boolean
75
84
  }
76
85
 
77
- export interface IPostcssOption {
86
+ interface IBasePostcssOption {
78
87
  autoprefixer?: TogglableOptions
79
88
  pxtransform?: TogglableOptions<IPxTransformOption>
80
89
  cssModules?: PostcssOption.cssModules
81
- url?: PostcssOption.url
82
90
  /** 插件 postcss-html-transform 相关配置, 一般启用了 @tarojs/plugin-html 插件才配置 */
83
91
  htmltransform?: IHtmlTransformOption
84
92
  [key: string]: any
85
93
  }
86
94
 
95
+ export type IPostcssOption<T = 'h5' | 'harmony' | 'mini'> = T extends 'h5'
96
+ ? IBasePostcssOption & { url?: PostcssOption.url }
97
+ : IBasePostcssOption
98
+
99
+ export type Config = ViteConfig | WebpackConfig
100
+
87
101
  export interface ICopyOptions {
88
102
  patterns: {
89
103
  from: string
90
104
  to: string
91
105
  ignore?: string[]
92
- transform?: Function
106
+ transform?: Func
93
107
  watch?: boolean
94
108
  }[]
95
109
  options: {