@tarojs/taro 3.7.0-beta.1 → 3.7.0-beta.3
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.
- package/package.json +11 -4
- package/types/api/ai/visionkit.d.ts +625 -54
- package/types/api/base/performance.d.ts +5 -5
- package/types/api/canvas/index.d.ts +67 -54
- package/types/api/device/accelerometer.d.ts +8 -6
- package/types/api/device/accessibility.d.ts +1 -1
- package/types/api/device/battery.d.ts +2 -2
- package/types/api/device/bluetooth-ble.d.ts +40 -17
- package/types/api/device/bluetooth-peripheral.d.ts +26 -26
- package/types/api/device/bluetooth.d.ts +37 -13
- package/types/api/device/calendar.d.ts +11 -1
- package/types/api/device/clipboard.d.ts +2 -2
- package/types/api/device/compass.d.ts +5 -5
- package/types/api/device/gyroscope.d.ts +4 -4
- package/types/api/device/iBeacon.d.ts +10 -8
- package/types/api/device/keyboard.d.ts +7 -5
- package/types/api/device/memory.d.ts +3 -4
- package/types/api/device/motion.d.ts +8 -6
- package/types/api/device/network.d.ts +12 -6
- package/types/api/device/nfc.d.ts +13 -13
- package/types/api/device/phone.d.ts +1 -1
- package/types/api/device/scan.d.ts +5 -3
- package/types/api/device/screen.d.ts +27 -11
- package/types/api/device/sms.d.ts +1 -1
- package/types/api/device/vibrate.d.ts +5 -5
- package/types/api/device/wifi.d.ts +25 -13
- package/types/api/media/camera.d.ts +9 -3
- package/types/api/open-api/device-voip.d.ts +2 -2
- package/types/api/open-api/login.d.ts +1 -1
- package/types/api/open-api/my-miniprogram.d.ts +2 -2
- package/types/api/open-api/privacy.d.ts +99 -0
- package/types/api/route/index.d.ts +1 -0
- package/types/api/skyline/index.d.ts +59 -0
- package/types/api/storage/cache-manager.d.ts +10 -10
- package/types/api/taro.extend.d.ts +1 -1
- package/types/api/ui/fonts.d.ts +4 -3
- package/types/compile/compiler.d.ts +7 -5
- package/types/compile/config/h5.d.ts +20 -10
- package/types/compile/config/mini.d.ts +36 -24
- package/types/compile/config/project.d.ts +8 -8
- package/types/compile/config/util.d.ts +18 -8
- package/types/compile/viteCompilerContext.d.ts +130 -0
- package/types/global.d.ts +1 -0
- package/types/index.d.ts +2 -0
- package/types/taro.api.d.ts +3 -0
- package/types/taro.component.d.ts +1 -1
- package/types/taro.config.d.ts +35 -4
|
@@ -90,15 +90,15 @@ declare module '../../index' {
|
|
|
90
90
|
* @supported alipay
|
|
91
91
|
*/
|
|
92
92
|
height: string
|
|
93
|
-
|
|
93
|
+
/** 视频文件的宽度。
|
|
94
94
|
* @supported alipay
|
|
95
95
|
*/
|
|
96
96
|
width: string
|
|
97
|
-
|
|
97
|
+
/** 视频文件的尺寸。
|
|
98
98
|
* @supported alipay
|
|
99
99
|
*/
|
|
100
100
|
size: string
|
|
101
|
-
|
|
101
|
+
/** 录制的持续时间。
|
|
102
102
|
* @supported alipay
|
|
103
103
|
*/
|
|
104
104
|
duration: string
|
|
@@ -152,6 +152,8 @@ declare module '../../index' {
|
|
|
152
152
|
normal
|
|
153
153
|
/** 低质量 */
|
|
154
154
|
low
|
|
155
|
+
/** 原图 */
|
|
156
|
+
original
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
|
|
@@ -192,6 +194,10 @@ declare module '../../index' {
|
|
|
192
194
|
|
|
193
195
|
interface TaroStatic {
|
|
194
196
|
/** 创建 camera 上下文 CameraContext 对象。
|
|
197
|
+
*
|
|
198
|
+
* ****
|
|
199
|
+
*
|
|
200
|
+
* 注:支付宝小程序需指定 camera 组件中的 id 属性
|
|
195
201
|
* @supported weapp, rn, tt, alipay
|
|
196
202
|
* @example
|
|
197
203
|
* ```tsx
|
|
@@ -20,7 +20,7 @@ declare module '../../index' {
|
|
|
20
20
|
/** 接口调用失败的回调函数 */
|
|
21
21
|
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
22
22
|
/** 接口调用成功的回调函数 */
|
|
23
|
-
success?: (result:
|
|
23
|
+
success?: (result: TaroGeneral.CallbackResult) => void
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -60,4 +60,4 @@ declare module '../../index' {
|
|
|
60
60
|
*/
|
|
61
61
|
getDeviceVoIPList(option: getDeviceVoIPList.Option): Promise<getDeviceVoIPList.SuccessCallbackResult>
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|
|
@@ -81,7 +81,7 @@ declare module '../../index' {
|
|
|
81
81
|
*
|
|
82
82
|
* 通过 Taro.login 接口获得的用户登录态拥有一定的时效性。用户越久未使用小程序,用户登录态越有可能失效。反之如果用户一直在使用小程序,则用户登录态一直保持有效。具体时效逻辑由微信维护,对开发者透明。开发者只需要调用 Taro.checkSession 接口检测当前用户登录态是否有效。
|
|
83
83
|
*
|
|
84
|
-
* 登录态过期后开发者可以再调用 Taro.login
|
|
84
|
+
* 登录态过期后开发者可以再调用 Taro.login 获取新的用户登录态。调用 Taro.checkSession 成功说明当前 session_key 未过期,调用失败说明 session_key 已过期。更多使用方法详见 [小程序登录](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html)。
|
|
85
85
|
* @supported weapp
|
|
86
86
|
* @example
|
|
87
87
|
* ```tsx
|
|
@@ -8,7 +8,7 @@ declare module '../../index' {
|
|
|
8
8
|
/** 接口调用失败的回调函数 */
|
|
9
9
|
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
10
10
|
/** 接口调用成功的回调函数 */
|
|
11
|
-
success?: (res:
|
|
11
|
+
success?: (res: SuccessCallbackResult) => void
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
|
|
@@ -23,6 +23,6 @@ declare module '../../index' {
|
|
|
23
23
|
* @supported weapp
|
|
24
24
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/my-miniprogram/wx.checkIsAddedToMyMiniProgram.html
|
|
25
25
|
*/
|
|
26
|
-
checkIsAddedToMyMiniProgram(option?: checkIsAddedToMyMiniProgram.Option):
|
|
26
|
+
checkIsAddedToMyMiniProgram(option?: checkIsAddedToMyMiniProgram.Option): void
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import Taro from '../../index'
|
|
2
|
+
|
|
3
|
+
declare module '../../index' {
|
|
4
|
+
namespace getPrivacySetting {
|
|
5
|
+
interface Option {
|
|
6
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
7
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
8
|
+
/** 接口调用失败的回调函数 */
|
|
9
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
10
|
+
/** 接口调用成功的回调函数 */
|
|
11
|
+
success?: (result: SuccessCallbackResult) => void
|
|
12
|
+
}
|
|
13
|
+
interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
|
|
14
|
+
/** 是否需要用户授权隐私协议(如果开发者没有在[mp后台-设置-服务内容声明-用户隐私保护指引]中声明隐私收集类型则会返回false;如果开发者声明了隐私收集,且用户之前同意过隐私协议则会返回false;如果开发者声明了隐私收集,且用户还没同意过则返回true;如果用户之前同意过、但后来小程序又新增了隐私收集类型也会返回true) */
|
|
15
|
+
needAuthorization: boolean
|
|
16
|
+
/** 隐私授权协议的名称 */
|
|
17
|
+
privacyContractName: string
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
namespace requirePrivacyAuthorize {
|
|
22
|
+
interface Option {
|
|
23
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
24
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
25
|
+
/** 接口调用失败的回调函数 */
|
|
26
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
27
|
+
/** 接口调用成功的回调函数 */
|
|
28
|
+
success?: (result: TaroGeneral.CallbackResult) => void
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
namespace openPrivacyContract {
|
|
33
|
+
interface Option {
|
|
34
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
35
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
36
|
+
/** 接口调用失败的回调函数 */
|
|
37
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
38
|
+
/** 接口调用成功的回调函数 */
|
|
39
|
+
success?: (result: TaroGeneral.CallbackResult) => void
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
namespace onNeedPrivacyAuthorization {
|
|
44
|
+
/**
|
|
45
|
+
* resolve 是 onNeedPrivacyAuthorization 的回调参数,是一个接口函数。
|
|
46
|
+
* 当触发 needPrivacyAuthorization 事件时,触发该事件的隐私接口或组件会处于 pending 状态。
|
|
47
|
+
* 如果调用 resolve({ buttonId: 'disagree-btn', event:'agree' }),则触发当前 needPrivacyAuthorization 事件的原隐私接口或组件会继续执行。其中 buttonId 为隐私同意授权按钮的id,为确保用户有同意的操作,基础库会检查对应的同意按钮是否被点击过。
|
|
48
|
+
* 如果调用 resolve({ event: 'disagree' }),则触发当前 needPrivacyAuthorization 事件的原隐私接口或组件会失败并返回 API:fail privacy permission is not authorized 的错误信息。
|
|
49
|
+
* 在调用 resolve({ event: 'agree'/'disagree' }) 之前,开发者可以调用 resolve({ event: 'exposureAuthorization' }) 把隐私弹窗曝光告知平台。
|
|
50
|
+
*/
|
|
51
|
+
interface ResolveOption {
|
|
52
|
+
/** 用户操作类型 */
|
|
53
|
+
event: 'exposureAuthorization' | 'agree' | 'disagree'
|
|
54
|
+
/** 同意授权按钮的id (仅event=agree时必填) */
|
|
55
|
+
buttonId?: string
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 触发本次 onNeedPrivacyAuthorization 事件的关联信息
|
|
59
|
+
*/
|
|
60
|
+
interface EventInfo {
|
|
61
|
+
referrer: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 隐私授权监听函数 */
|
|
65
|
+
type Listener = (
|
|
66
|
+
/** 事件回调函数 */
|
|
67
|
+
resolve: (option: ResolveOption) => void,
|
|
68
|
+
/** 关联事件信息 */
|
|
69
|
+
eventInfo: EventInfo
|
|
70
|
+
) => void
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface TaroStatic {
|
|
74
|
+
/**
|
|
75
|
+
* 查询隐私授权情况。隐私合规开发指南详情可见《小程序隐私协议开发指南》
|
|
76
|
+
* @supported weapp
|
|
77
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/privacy/wx.getPrivacySetting.html
|
|
78
|
+
*/
|
|
79
|
+
getPrivacySetting(option?: getPrivacySetting.Option): void
|
|
80
|
+
/**
|
|
81
|
+
* 跳转至隐私协议页面。隐私合规开发指南详情可见《小程序隐私协议开发指南》
|
|
82
|
+
* @supported weapp
|
|
83
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/privacy/wx.openPrivacyContract.html
|
|
84
|
+
*/
|
|
85
|
+
openPrivacyContract(option?: openPrivacyContract.Option): void
|
|
86
|
+
/**
|
|
87
|
+
* 模拟隐私接口调用,并触发隐私弹窗逻辑。隐私合规开发指南详情可见《小程序隐私协议开发指南》
|
|
88
|
+
* @supported weapp
|
|
89
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/privacy/wx.requirePrivacyAuthorize.html
|
|
90
|
+
*/
|
|
91
|
+
requirePrivacyAuthorize(option?: requirePrivacyAuthorize.Option): void
|
|
92
|
+
/**
|
|
93
|
+
* 监听隐私接口需要用户授权事件。当需要用户进行隐私授权时会触发。触发该事件时,开发者需要弹出隐私协议说明,并在用户同意或拒绝授权后调用回调接口 resolve 触发原隐私接口或组件继续执行。隐私合规开发指南详情可见《小程序隐私协议开发指南》
|
|
94
|
+
* @supported weapp
|
|
95
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/privacy/wx.onNeedPrivacyAuthorization.html
|
|
96
|
+
*/
|
|
97
|
+
onNeedPrivacyAuthorization(listener: onNeedPrivacyAuthorization.Listener): void
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -196,6 +196,7 @@ declare module '../../index' {
|
|
|
196
196
|
|
|
197
197
|
/** 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages 获取当前的页面栈,决定需要返回几层。
|
|
198
198
|
* @supported weapp, h5, rn, tt
|
|
199
|
+
* @h5 若入参 delta 大于现有页面数时,返回应用打开的第一个页面(如果想要返回首页请使用 reLaunch 方法)。
|
|
199
200
|
* @example
|
|
200
201
|
* ```tsx
|
|
201
202
|
* // 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,而 redirectTo 方法则不会。见下方示例代码
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import Taro from '../../index'
|
|
2
|
+
|
|
3
|
+
declare module '../../index' {
|
|
4
|
+
/**
|
|
5
|
+
* Snapshot 实例,可通过 SelectorQuery 获取。
|
|
6
|
+
*
|
|
7
|
+
* Snapshot 通过 id 跟一个 snapshot 组件绑定,操作对应的 snapshot 组件。
|
|
8
|
+
* @supported weapp
|
|
9
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/skyline/Snapshot.html
|
|
10
|
+
*/
|
|
11
|
+
interface Snapshot {
|
|
12
|
+
/**
|
|
13
|
+
* 画布宽度
|
|
14
|
+
*/
|
|
15
|
+
width: number
|
|
16
|
+
/**
|
|
17
|
+
* 画布高度
|
|
18
|
+
*/
|
|
19
|
+
height: number
|
|
20
|
+
/**
|
|
21
|
+
* 对 snapshot 组件子树进行截图
|
|
22
|
+
* @param option
|
|
23
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/skyline/Snapshot.takeSnapshot.html
|
|
24
|
+
*/
|
|
25
|
+
takeSnapshot(option: Snapshot.TakeSnapshot.Option): Promise<TaroGeneral.CallbackResult>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
namespace Snapshot {
|
|
29
|
+
namespace TakeSnapshot {
|
|
30
|
+
interface Option {
|
|
31
|
+
/**
|
|
32
|
+
* 截图导出类型,'file' 保存到临时文件目录或 'arraybuffer' 返回图片二进制数据,默认值为 'file'
|
|
33
|
+
*/
|
|
34
|
+
type: string
|
|
35
|
+
/**
|
|
36
|
+
* 截图文件格式,'rgba' 或 'png',默认值为 'png'
|
|
37
|
+
*/
|
|
38
|
+
format: string
|
|
39
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
40
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
41
|
+
/** 接口调用失败的回调函数 */
|
|
42
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
43
|
+
/** 接口调用成功的回调函数 */
|
|
44
|
+
success?: (res: SuccessCallbackResult) => void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface SuccessCallbackResult {
|
|
48
|
+
/**
|
|
49
|
+
* 截图保存的临时文件路径,当 type 为 file 该字段生效
|
|
50
|
+
*/
|
|
51
|
+
tempFilePath: string
|
|
52
|
+
/**
|
|
53
|
+
* 截图对应的二进制数据,当 type 为 arraybuffer 该字段生效
|
|
54
|
+
*/
|
|
55
|
+
data: string
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -26,7 +26,7 @@ declare module '../../index' {
|
|
|
26
26
|
* @supported weapp
|
|
27
27
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteCache.html
|
|
28
28
|
*/
|
|
29
|
-
deleteCache(
|
|
29
|
+
deleteCache(
|
|
30
30
|
/** 缓存 id */
|
|
31
31
|
id: string
|
|
32
32
|
): void
|
|
@@ -40,7 +40,7 @@ declare module '../../index' {
|
|
|
40
40
|
): void
|
|
41
41
|
/** 删除规则,同时会删除对应规则下所有缓存
|
|
42
42
|
* @supported weapp
|
|
43
|
-
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteRule.html
|
|
43
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteRule.html
|
|
44
44
|
*/
|
|
45
45
|
deleteRule(
|
|
46
46
|
/** 规则 id */
|
|
@@ -67,17 +67,17 @@ declare module '../../index' {
|
|
|
67
67
|
/** 事件名称 */
|
|
68
68
|
eventName: string,
|
|
69
69
|
/** 事件监听函数 */
|
|
70
|
-
handler:
|
|
70
|
+
handler: TaroGeneral.EventCallback
|
|
71
71
|
): void
|
|
72
72
|
/** 监听事件
|
|
73
73
|
* @supported weapp
|
|
74
74
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.on.html
|
|
75
75
|
*/
|
|
76
|
-
on(
|
|
76
|
+
on(
|
|
77
77
|
/** 事件名称 */
|
|
78
78
|
eventName: keyof CacheManager.OnEventName,
|
|
79
79
|
/** 事件监听函数 */
|
|
80
|
-
handler:
|
|
80
|
+
handler: TaroGeneral.EventCallback
|
|
81
81
|
): void
|
|
82
82
|
/** 开启缓存,仅在 mode 为 none 时生效,调用后缓存管理器的 state 会置为 1
|
|
83
83
|
* @supported weapp
|
|
@@ -117,7 +117,7 @@ declare module '../../index' {
|
|
|
117
117
|
method: string
|
|
118
118
|
/** uri 匹配规则,可参考规则字符串写法和正则写法 */
|
|
119
119
|
url: any
|
|
120
|
-
/**
|
|
120
|
+
/**
|
|
121
121
|
* 缓存有效时间,单位为 ms,不填则默认取缓存管理器全局的缓存有效时间
|
|
122
122
|
* @default 7 * 24 * 60 * 60 * 1000
|
|
123
123
|
*/
|
|
@@ -189,10 +189,10 @@ declare module '../../index' {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
interface TaroStatic {
|
|
192
|
-
/**
|
|
193
|
-
* @supported
|
|
194
|
-
* @see
|
|
192
|
+
/** 创建缓存管理器
|
|
193
|
+
* @supported weapp
|
|
194
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/wx.createCacheManager.html
|
|
195
195
|
*/
|
|
196
196
|
createCacheManager(option: createCacheManager.Option): CacheManager
|
|
197
197
|
}
|
|
198
|
-
}
|
|
198
|
+
}
|
package/types/api/ui/fonts.d.ts
CHANGED
|
@@ -54,13 +54,14 @@ declare module '../../index' {
|
|
|
54
54
|
/** 动态加载网络字体。文件地址需为下载类型。iOS 仅支持 https 格式文件地址。
|
|
55
55
|
*
|
|
56
56
|
* 注意:
|
|
57
|
-
* 1. 字体文件返回的
|
|
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. 工具里提示
|
|
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({
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { swc } from '@tarojs/helper'
|
|
2
2
|
import type Webpack from 'webpack'
|
|
3
3
|
|
|
4
|
-
type CompilerTypes =
|
|
4
|
+
export type CompilerTypes = CompilerWebpackTypes | 'vite'
|
|
5
|
+
|
|
6
|
+
export type CompilerWebpackTypes = 'webpack5' | 'webpack4'
|
|
5
7
|
|
|
6
8
|
interface IPrebundle {
|
|
7
9
|
enable?: boolean
|
|
@@ -17,10 +19,10 @@ interface IPrebundle {
|
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
interface ICompiler {
|
|
21
|
-
type:
|
|
22
|
+
interface ICompiler<T> {
|
|
23
|
+
type: T
|
|
22
24
|
prebundle?: IPrebundle
|
|
23
|
-
vitePlugins?: any
|
|
25
|
+
vitePlugins?: any
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
export type Compiler
|
|
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 { 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
|
-
/**
|
|
39
|
-
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?:
|
|
89
|
+
mediaUrlLoaderOption?: IUrlLoaderOption
|
|
83
90
|
|
|
84
91
|
/** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
85
|
-
fontUrlLoaderOption?:
|
|
92
|
+
fontUrlLoaderOption?: IUrlLoaderOption
|
|
86
93
|
|
|
87
94
|
/** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
88
|
-
imageUrlLoaderOption?:
|
|
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,17 @@ 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?:
|
|
111
|
-
include?:
|
|
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
|
|
113
123
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
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 { CompilerTypes, CompilerWebpackTypes } from '../compiler'
|
|
4
6
|
|
|
5
7
|
interface Runtime {
|
|
6
8
|
enableInnerHTML: boolean
|
|
@@ -12,7 +14,25 @@ interface Runtime {
|
|
|
12
14
|
enableMutationObserver: boolean
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
|
|
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
|
-
/**
|
|
41
|
-
output
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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?:
|
|
83
|
+
mediaUrlLoaderOption?: IUrlLoaderOption
|
|
73
84
|
|
|
74
85
|
/** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
75
|
-
fontUrlLoaderOption?:
|
|
86
|
+
fontUrlLoaderOption?: IUrlLoaderOption
|
|
76
87
|
|
|
77
88
|
/** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
78
|
-
imageUrlLoaderOption?:
|
|
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,8 +105,9 @@ export interface IMiniAppConfig {
|
|
|
94
105
|
|
|
95
106
|
/** 小程序编译过程的相关配置 */
|
|
96
107
|
compile?: {
|
|
97
|
-
exclude?:
|
|
98
|
-
include?:
|
|
108
|
+
exclude?: (string | RegExp)[]
|
|
109
|
+
include?: (string | RegExp)[]
|
|
110
|
+
filter?: (filename: string) => boolean
|
|
99
111
|
}
|
|
100
112
|
|
|
101
113
|
/** 插件内部使用 */
|
|
@@ -104,7 +116,7 @@ export interface IMiniAppConfig {
|
|
|
104
116
|
|
|
105
117
|
export interface IMiniFilesConfig {
|
|
106
118
|
[configName: string]: {
|
|
107
|
-
content:
|
|
119
|
+
content: any
|
|
108
120
|
path: string
|
|
109
121
|
}
|
|
110
122
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type Webpack from 'webpack'
|
|
2
2
|
import type Chain from 'webpack-chain'
|
|
3
3
|
import { type Input } from 'postcss'
|
|
4
|
-
import type { Compiler } from '../compiler'
|
|
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'
|
|
@@ -203,7 +203,7 @@ export interface IProjectBaseConfig {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
/** 暴露出来给 config/index 使用的配置类型,参考 https://github.com/NervJS/taro-doctor/blob/main/assets/config_schema.json */
|
|
206
|
-
export interface IProjectConfig {
|
|
206
|
+
export interface IProjectConfig<T extends CompilerTypes = CompilerWebpackTypes> {
|
|
207
207
|
/** 项目名称 */
|
|
208
208
|
projectName?: string
|
|
209
209
|
|
|
@@ -295,20 +295,20 @@ export interface IProjectConfig {
|
|
|
295
295
|
/** 使用的开发框架。可选值:react、preact、nerv、vue、vue3 */
|
|
296
296
|
framework?: 'react' | 'preact' | 'nerv' | 'vue' | 'vue3'
|
|
297
297
|
|
|
298
|
-
/** 使用的编译工具。可选值:webpack4、webpack5 */
|
|
299
|
-
compiler?: Compiler
|
|
300
|
-
|
|
301
298
|
/** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
|
|
302
299
|
cache?: ICache
|
|
303
300
|
|
|
304
301
|
/** 控制 Taro 编译日志的输出方式 */
|
|
305
302
|
logger?: ILogger
|
|
306
303
|
|
|
307
|
-
/**
|
|
308
|
-
|
|
304
|
+
/** 使用的编译工具。可选值:webpack4、webpack5、vite */
|
|
305
|
+
compiler?: Compiler<T>
|
|
309
306
|
|
|
310
307
|
/** 专属于 H5 的配置 */
|
|
311
|
-
h5?: IH5Config
|
|
308
|
+
h5?: IH5Config<T>
|
|
309
|
+
|
|
310
|
+
/** 专属于小程序的配置 */
|
|
311
|
+
mini?: IMiniAppConfig<T>
|
|
312
312
|
|
|
313
313
|
/** 专属于 RN 的配置 */
|
|
314
314
|
rn?: IRNConfig
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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,31 @@ 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
|
+
/** filter 回调函数,可 exclude 不处理的文件 */
|
|
81
|
+
exclude?: (fileName: string) => boolean
|
|
75
82
|
}
|
|
76
83
|
|
|
77
|
-
|
|
84
|
+
interface IBasePostcssOption {
|
|
78
85
|
autoprefixer?: TogglableOptions
|
|
79
86
|
pxtransform?: TogglableOptions<IPxTransformOption>
|
|
80
87
|
cssModules?: PostcssOption.cssModules
|
|
81
|
-
url?: PostcssOption.url
|
|
82
88
|
/** 插件 postcss-html-transform 相关配置, 一般启用了 @tarojs/plugin-html 插件才配置 */
|
|
83
89
|
htmltransform?: IHtmlTransformOption
|
|
84
90
|
[key: string]: any
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
export type IPostcssOption<T = 'h5' | 'mini'> = T extends 'h5'
|
|
94
|
+
? IBasePostcssOption & { url?: PostcssOption.url }
|
|
95
|
+
: IBasePostcssOption
|
|
96
|
+
|
|
87
97
|
export interface ICopyOptions {
|
|
88
98
|
patterns: {
|
|
89
99
|
from: string
|
|
90
100
|
to: string
|
|
91
101
|
ignore?: string[]
|
|
92
|
-
transform?:
|
|
102
|
+
transform?: Func
|
|
93
103
|
watch?: boolean
|
|
94
104
|
}[]
|
|
95
105
|
options: {
|