@tarojs/taro 3.8.0-canary.0 → 4.0.0-beta.0

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 (73) hide show
  1. package/html.css +9 -0
  2. package/package.json +11 -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/performance.d.ts +5 -5
  7. package/types/api/base/system.d.ts +2 -2
  8. package/types/api/base/weapp/app-event.d.ts +4 -4
  9. package/types/api/canvas/index.d.ts +67 -54
  10. package/types/api/data-analysis/index.d.ts +51 -1
  11. package/types/api/device/accelerometer.d.ts +8 -6
  12. package/types/api/device/accessibility.d.ts +1 -1
  13. package/types/api/device/battery.d.ts +3 -3
  14. package/types/api/device/bluetooth-ble.d.ts +40 -17
  15. package/types/api/device/bluetooth-peripheral.d.ts +26 -26
  16. package/types/api/device/bluetooth.d.ts +37 -13
  17. package/types/api/device/calendar.d.ts +11 -1
  18. package/types/api/device/clipboard.d.ts +17 -17
  19. package/types/api/device/compass.d.ts +5 -5
  20. package/types/api/device/gyroscope.d.ts +4 -4
  21. package/types/api/device/iBeacon.d.ts +10 -8
  22. package/types/api/device/keyboard.d.ts +7 -5
  23. package/types/api/device/memory.d.ts +3 -4
  24. package/types/api/device/motion.d.ts +8 -6
  25. package/types/api/device/network.d.ts +12 -6
  26. package/types/api/device/nfc.d.ts +13 -13
  27. package/types/api/device/phone.d.ts +1 -1
  28. package/types/api/device/scan.d.ts +5 -3
  29. package/types/api/device/screen.d.ts +28 -12
  30. package/types/api/device/sms.d.ts +1 -1
  31. package/types/api/device/vibrate.d.ts +5 -5
  32. package/types/api/device/wifi.d.ts +25 -13
  33. package/types/api/files/index.d.ts +71 -41
  34. package/types/api/location/index.d.ts +166 -18
  35. package/types/api/media/audio.d.ts +50 -30
  36. package/types/api/media/camera.d.ts +6 -3
  37. package/types/api/media/image.d.ts +1 -1
  38. package/types/api/navigate/index.d.ts +2 -0
  39. package/types/api/network/download.d.ts +2 -10
  40. package/types/api/network/request.d.ts +1 -1
  41. package/types/api/network/upload.d.ts +2 -10
  42. package/types/api/open-api/device-voip.d.ts +2 -2
  43. package/types/api/open-api/login.d.ts +1 -1
  44. package/types/api/open-api/my-miniprogram.d.ts +2 -2
  45. package/types/api/open-api/privacy.d.ts +99 -0
  46. package/types/api/route/index.d.ts +8 -5
  47. package/types/api/skyline/index.d.ts +59 -0
  48. package/types/api/storage/background-fetch.d.ts +63 -11
  49. package/types/api/storage/cache-manager.d.ts +61 -10
  50. package/types/api/storage/index.d.ts +125 -10
  51. package/types/api/taro.extend.d.ts +9 -3
  52. package/types/api/ui/animation.d.ts +1 -1
  53. package/types/api/ui/fonts.d.ts +4 -3
  54. package/types/api/ui/interaction.d.ts +4 -4
  55. package/types/api/ui/navigation-bar.d.ts +5 -5
  56. package/types/api/ui/pull-down-refresh.d.ts +2 -2
  57. package/types/api/ui/scroll.d.ts +1 -1
  58. package/types/api/ui/tab-bar.d.ts +7 -7
  59. package/types/api/wxml/index.d.ts +4 -4
  60. package/types/compile/compiler.d.ts +7 -4
  61. package/types/compile/config/h5.d.ts +23 -10
  62. package/types/compile/config/harmony.d.ts +77 -0
  63. package/types/compile/config/index.d.ts +1 -0
  64. package/types/compile/config/mini.d.ts +58 -30
  65. package/types/compile/config/plugin.d.ts +34 -0
  66. package/types/compile/config/project.d.ts +26 -13
  67. package/types/compile/config/util.d.ts +22 -8
  68. package/types/compile/viteCompilerContext.d.ts +149 -0
  69. package/types/global.d.ts +1 -0
  70. package/types/index.d.ts +2 -0
  71. package/types/taro.api.d.ts +3 -0
  72. package/types/taro.component.d.ts +2 -1
  73. package/types/taro.config.d.ts +41 -4
@@ -83,7 +83,7 @@ declare module '../index' {
83
83
  /** 尺寸转换
84
84
  * @supported global
85
85
  */
86
- pxTransform(size: number, designWidth?: number): string
86
+ pxTransform(size: number): string
87
87
 
88
88
  /** 尺寸转换初始化
89
89
  * @supported global
@@ -97,7 +97,7 @@ declare module '../index' {
97
97
  }): void
98
98
 
99
99
  /** 小程序获取和 Taro 相关的 App 信息
100
- * @supported weapp, alipay, jd, qq, swan, tt, h5
100
+ * @supported weapp, alipay, jd, qq, swan, tt, h5, harmony
101
101
  */
102
102
  getAppInfo(): getAppInfo.AppInfo
103
103
 
@@ -127,7 +127,13 @@ declare module '../index' {
127
127
  /** 小程序引用插件 JS 接口
128
128
  * @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
129
129
  */
130
- requirePlugin(pluginName: string): any
130
+ requirePlugin: {
131
+ (pluginName: string): any
132
+ /** @supported weapp */
133
+ (pluginName: string, success?: (mod: any) => any, error?: (e: { mod: any; errMsg: string }) => any): any;
134
+ /** @supported weapp */
135
+ async?: (pluginName: string) => Promise<any>
136
+ }
131
137
 
132
138
  /** 获取当前页面实例
133
139
  * @supported global
@@ -410,7 +410,7 @@ declare module '../../index' {
410
410
 
411
411
  interface TaroStatic {
412
412
  /** 创建一个动画实例 [animation](../Animation)。调用实例的方法来描述动画。最后通过动画实例的 export 方法导出动画数据传递给组件的 animation 属性。
413
- * @supported weapp, h5, tt
413
+ * @supported weapp, tt, h5, harmony
414
414
  * @example
415
415
  * ```tsx
416
416
  * var animation = Taro.createAnimation({
@@ -54,13 +54,14 @@ declare module '../../index' {
54
54
  /** 动态加载网络字体。文件地址需为下载类型。iOS 仅支持 https 格式文件地址。
55
55
  *
56
56
  * 注意:
57
- * 1. 字体文件返回的 contet-type 参考 [font](https://www.iana.org/assignments/media-types/media-types.xhtml#font),格式不正确时会解析失败。
57
+ * 1. 字体文件返回的 context-type 参考 [font](https://www.iana.org/assignments/media-types/media-types.xhtml#font),格式不正确时会解析失败。
58
58
  * 2. 字体链接必须是https(ios不支持http)
59
59
  * 3. 字体链接必须是同源下的,或开启了cors支持,小程序的域名是`servicewechat.com`
60
60
  * 4. canvas等原生组件不支持使用接口添加的字体
61
- * 5. 工具里提示 Faild to load font可以忽略
62
- * @supported weapp, h5
61
+ * 5. 工具里提示 Failed to load font 可以忽略
62
+ * @supported weapp, alipay, h5
63
63
  * @h5 不支持 global (默认全局加载)
64
+ * @alipay source 地址格式为 `url('https://...')`,而不是单纯 URL 地址
64
65
  * @example
65
66
  * ```tsx
66
67
  * Taro.loadFontFace({
@@ -160,7 +160,7 @@ declare module '../../index' {
160
160
  * **注意**
161
161
  * - Taro.showLoading 和 Taro.showToast 同时只能显示一个
162
162
  * - Taro.showToast 应与 Taro.hideToast 配对使用
163
- * @supported weapp, h5, rn, tt
163
+ * @supported weapp, h5, rn, tt, harmony
164
164
  * @example
165
165
  * ```tsx
166
166
  * Taro.showToast({
@@ -177,7 +177,7 @@ declare module '../../index' {
177
177
  * **注意**
178
178
  * - Android 6.7.2 以下版本,点击取消或蒙层时,回调 fail, errMsg 为 "fail cancel";
179
179
  * - Android 6.7.2 及以上版本 和 iOS 点击蒙层不会关闭模态弹窗,所以尽量避免使用「取消」分支中实现业务逻辑
180
- * @supported weapp, h5, rn, tt
180
+ * @supported weapp, h5, rn, tt, harmony
181
181
  * @example
182
182
  * ```tsx
183
183
  * Taro.showModal({
@@ -220,7 +220,7 @@ declare module '../../index' {
220
220
  * **注意**
221
221
  * - Android 6.7.2 以下版本,点击取消或蒙层时,回调 fail, errMsg 为 "fail cancel";
222
222
  * - Android 6.7.2 及以上版本 和 iOS 点击蒙层不会关闭模态弹窗,所以尽量避免使用「取消」分支中实现业务逻辑
223
- * @supported weapp, h5, rn, tt
223
+ * @supported weapp, h5, rn, tt, harmony
224
224
  * @example
225
225
  * ```tsx
226
226
  * Taro.showActionSheet({
@@ -238,7 +238,7 @@ declare module '../../index' {
238
238
  showActionSheet(option: showActionSheet.Option): Promise<showActionSheet.SuccessCallbackResult>
239
239
 
240
240
  /** 隐藏消息提示框
241
- * @supported weapp, h5, rn, tt
241
+ * @supported weapp, h5, rn, tt, harmony
242
242
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/interaction/wx.hideToast.html
243
243
  */
244
244
  hideToast(option?: hideToast.Option): void
@@ -79,13 +79,13 @@ declare module '../../index' {
79
79
 
80
80
  interface TaroStatic {
81
81
  /** 在当前页面显示导航条加载动画
82
- * @supported weapp, rn, tt
82
+ * @supported weapp, rn, tt, harmony
83
83
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/navigation-bar/wx.showNavigationBarLoading.html
84
84
  */
85
85
  showNavigationBarLoading(option?: showNavigationBarLoading.Option): void
86
86
 
87
87
  /** 动态设置当前页面的标题
88
- * @supported weapp, alipay, h5, rn, tt
88
+ * @supported weapp, alipay, tt, h5, rn, harmony
89
89
  * @example
90
90
  * ```tsx
91
91
  * Taro.setNavigationBarTitle({
@@ -97,7 +97,7 @@ declare module '../../index' {
97
97
  setNavigationBarTitle(option: setNavigationBarTitle.Option): Promise<TaroGeneral.CallbackResult>
98
98
 
99
99
  /** 设置页面导航条颜色
100
- * @supported weapp, h5, rn, tt
100
+ * @supported weapp, tt, h5, rn, harmony
101
101
  * @h5 不支持 animation 参数
102
102
  * @rn 不支持 animation 参数
103
103
  * @example
@@ -116,13 +116,13 @@ declare module '../../index' {
116
116
  setNavigationBarColor(option: setNavigationBarColor.Option): Promise<TaroGeneral.CallbackResult>
117
117
 
118
118
  /** 在当前页面隐藏导航条加载动画
119
- * @supported weapp, rn, tt
119
+ * @supported weapp, rn, tt, harmony
120
120
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/navigation-bar/wx.hideNavigationBarLoading.html
121
121
  */
122
122
  hideNavigationBarLoading(option?: hideNavigationBarLoading.Option): void
123
123
 
124
124
  /** 隐藏返回首页按钮。微信7.0.7版本起,当用户打开的小程序最底层页面是非首页时,默认展示“返回首页”按钮,开发者可在页面 onShow 中调用 hideHomeButton 进行隐藏。
125
- * @supported weapp, tt
125
+ * @supported weapp, tt, harmony
126
126
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/navigation-bar/wx.hideHomeButton.html
127
127
  */
128
128
  hideHomeButton(option?: hideHomeButton.Option): Promise<TaroGeneral.CallbackResult>
@@ -25,7 +25,7 @@ declare module '../../index' {
25
25
 
26
26
  interface TaroStatic {
27
27
  /** 停止当前页面下拉刷新。
28
- * @supported weapp, h5, rn, tt
28
+ * @supported weapp, h5, rn, tt, harmony
29
29
  * @example
30
30
  * ```tsx
31
31
  * onPullDownRefresh: function (){
@@ -37,7 +37,7 @@ declare module '../../index' {
37
37
  stopPullDownRefresh(option?: stopPullDownRefresh.Option): void
38
38
 
39
39
  /** 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
40
- * @supported weapp, h5, rn, tt
40
+ * @supported weapp, h5, rn, tt, harmony
41
41
  * @rn 无动画效果
42
42
  * @example
43
43
  * ```tsx
@@ -99,7 +99,7 @@ declare module '../../index' {
99
99
  * - 后代选择器:.the-ancestor .the-descendant
100
100
  * - 跨自定义组件的后代选择器:.the-ancestor >>> .the-descendant
101
101
  * - 多选择器的并集:#a-node, .some-other-nodes
102
- * @supported weapp, h5, rn, tt
102
+ * @supported weapp, h5, rn, tt, harmony
103
103
  * @example
104
104
  * ```tsx
105
105
  * Taro.pageScrollTo({
@@ -121,13 +121,13 @@ declare module '../../index' {
121
121
 
122
122
  interface TaroStatic {
123
123
  /** 显示 tabBar 某一项的右上角的红点
124
- * @supported weapp, h5, rn, tt
124
+ * @supported weapp, h5, rn, tt, harmony
125
125
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.showTabBarRedDot.html
126
126
  */
127
127
  showTabBarRedDot(option: showTabBarRedDot.Option): Promise<TaroGeneral.CallbackResult>
128
128
 
129
129
  /** 显示 tabBar
130
- * @supported weapp, h5, rn, tt
130
+ * @supported weapp, h5, rn, tt, harmony
131
131
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.showTabBar.html
132
132
  */
133
133
  showTabBar(option?: showTabBar.Option): Promise<TaroGeneral.CallbackResult>
@@ -148,7 +148,7 @@ declare module '../../index' {
148
148
  setTabBarStyle(option?: setTabBarStyle.Option): Promise<TaroGeneral.CallbackResult>
149
149
 
150
150
  /** 动态设置 tabBar 某一项的内容,`2.7.0` 起图片支持临时文件和网络文件。
151
- * @supported weapp, h5, rn, tt
151
+ * @supported weapp, h5, rn, tt, harmony
152
152
  * @example
153
153
  * ```tsx
154
154
  * Taro.setTabBarItem({
@@ -163,7 +163,7 @@ declare module '../../index' {
163
163
  setTabBarItem(option: setTabBarItem.Option): Promise<TaroGeneral.CallbackResult>
164
164
 
165
165
  /** 为 tabBar 某一项的右上角添加文本
166
- * @supported weapp, h5, rn, tt
166
+ * @supported weapp, h5, rn, tt, harmony
167
167
  * @example
168
168
  * ```tsx
169
169
  * Taro.setTabBarBadge({
@@ -176,19 +176,19 @@ declare module '../../index' {
176
176
  setTabBarBadge(option: setTabBarBadge.Option): Promise<TaroGeneral.CallbackResult>
177
177
 
178
178
  /** 移除 tabBar 某一项右上角的文本
179
- * @supported weapp, h5, rn, tt
179
+ * @supported weapp, h5, rn, tt, harmony
180
180
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.removeTabBarBadge.html
181
181
  */
182
182
  removeTabBarBadge(option: removeTabBarBadge.Option): Promise<TaroGeneral.CallbackResult>
183
183
 
184
184
  /** 隐藏 tabBar 某一项的右上角的红点
185
- * @supported weapp, h5, rn, tt
185
+ * @supported weapp, h5, rn, tt, harmony
186
186
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.hideTabBarRedDot.html
187
187
  */
188
188
  hideTabBarRedDot(option: hideTabBarRedDot.Option): Promise<TaroGeneral.CallbackResult>
189
189
 
190
190
  /** 隐藏 tabBar
191
- * @supported weapp, h5, rn, tt
191
+ * @supported weapp, h5, rn, tt, harmony
192
192
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.hideTabBar.html
193
193
  */
194
194
  hideTabBar(option?: hideTabBar.Option): Promise<TaroGeneral.CallbackResult>
@@ -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
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
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
  */
@@ -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,10 @@ 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
23
26
  }
24
27
 
25
- export type Compiler = CompilerTypes | ICompiler
28
+ 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,77 @@
1
+ import type Chain from 'webpack-chain'
2
+ import type { IOption, IPostcssOption, IUrlLoaderOption } from './util'
3
+
4
+ export interface IHarmonyConfig<T extends CompilerTypes = CompilerWebpackTypes> {
5
+ /** Harmony 项目地址 */
6
+ projectPath: string
7
+
8
+ /** hap 名
9
+ * @default "entry"
10
+ */
11
+ hapName?: string
12
+
13
+ /** 应用名称
14
+ * @default "default"
15
+ */
16
+ name?: string
17
+
18
+ /** 用于告诉 Taro 编译器需要抽取的公共文件 */
19
+ commonChunks?: string[] | ((commonChunks: string[]) => string[])
20
+
21
+ /** Harmony 编译过程的相关配置 */
22
+ compile?: {
23
+ exclude?: any[]
24
+ include?: any[]
25
+ filter?: (filename: string) => boolean
26
+ }
27
+
28
+ /** 用于控制是否生成 js、css 对应的 sourceMap (默认值:watch 模式下为 true,否则为 false) */
29
+ enableSourceMap?: boolean
30
+
31
+ /** 默认值:'cheap-module-source-map', 具体参考[Webpack devtool 配置](https://webpack.js.org/configuration/devtool/#devtool) */
32
+ sourceMapType?: string
33
+
34
+ /** 指定 React 框架相关的代码是否使用开发环境(未压缩)代码,默认使用生产环境(压缩后)代码 */
35
+ debugReact?: boolean
36
+
37
+ /**
38
+ * 自定义 Webpack 配置
39
+ * @param chain [webpackChain](https://github.com/neutrinojs/webpack-chain) 对象
40
+ * @param webpack webpack 实例
41
+ */
42
+ webpackChain?: (chain: Chain, webpack: typeof Webpack) => void
43
+
44
+ /** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/)
45
+ * vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/)
46
+ */
47
+ output?: T extends 'vite'
48
+ ? Pick<RollupOutputOptions, 'chunkFileNames'> & OutputExt
49
+ : Webpack.Configuration['output'] & OutputExt
50
+
51
+ /** 配置 postcss 相关插件 */
52
+ postcss?: IPostcssOption<'harmony'>
53
+
54
+ /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
55
+ cssLoaderOption?: IOption
56
+
57
+ /** [sass-loader](https://github.com/webpack-contrib/sass-loader) 的附加配置 */
58
+ sassLoaderOption?: IOption
59
+
60
+ /** [less-loader](https://github.com/webpack-contrib/less-loader) 的附加配置 */
61
+ lessLoaderOption?: IOption
62
+
63
+ /** [stylus-loader](https://github.com/shama/stylus-loader) 的附加配置 */
64
+ stylusLoaderOption?: IOption
65
+
66
+ /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
67
+ mediaUrlLoaderOption?: IUrlLoaderOption
68
+
69
+ /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
70
+ fontUrlLoaderOption?: IUrlLoaderOption
71
+
72
+ /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
73
+ imageUrlLoaderOption?: IUrlLoaderOption
74
+
75
+ /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
76
+ miniCssExtractPluginOption?: IOption
77
+ }
@@ -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
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
+ }