@tarojs/taro 3.7.0-alpha.0 → 3.7.0-alpha.10

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 (42) hide show
  1. package/package.json +9 -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/alipay/index.d.ts +43 -0
  5. package/types/api/base/crypto.d.ts +18 -4
  6. package/types/api/base/index.d.ts +2 -2
  7. package/types/api/base/performance.d.ts +63 -0
  8. package/types/api/base/system.d.ts +65 -0
  9. package/types/api/base/weapp/app-event.d.ts +18 -18
  10. package/types/api/device/calendar.d.ts +2 -2
  11. package/types/api/device/screen.d.ts +61 -0
  12. package/types/api/device/sms.d.ts +26 -0
  13. package/types/api/media/audio.d.ts +50 -30
  14. package/types/api/media/image.d.ts +40 -17
  15. package/types/api/media/live.d.ts +52 -0
  16. package/types/api/media/video.d.ts +64 -23
  17. package/types/api/media/voip.d.ts +103 -0
  18. package/types/api/network/download.d.ts +2 -10
  19. package/types/api/network/request.d.ts +84 -24
  20. package/types/api/network/upload.d.ts +2 -10
  21. package/types/api/open-api/address.d.ts +12 -10
  22. package/types/api/open-api/channels.d.ts +31 -0
  23. package/types/api/open-api/device-voip.d.ts +63 -0
  24. package/types/api/route/index.d.ts +2 -0
  25. package/types/api/share/index.d.ts +1 -1
  26. package/types/api/storage/cache-manager.d.ts +198 -0
  27. package/types/api/taro.extend.d.ts +223 -0
  28. package/types/{taro.hooks.d.ts → api/taro.hooks.d.ts} +4 -4
  29. package/types/api/ui/navigation-bar.d.ts +1 -1
  30. package/types/compile/compiler.d.ts +1 -1
  31. package/types/compile/config/h5.d.ts +63 -2
  32. package/types/compile/config/mini.d.ts +67 -5
  33. package/types/compile/config/project.d.ts +239 -17
  34. package/types/compile/config/rn.d.ts +64 -0
  35. package/types/compile/config/util.d.ts +62 -4
  36. package/types/compile/hooks.d.ts +1 -1
  37. package/types/global.d.ts +8 -8
  38. package/types/index.d.ts +7 -7
  39. package/types/taro.api.d.ts +8 -1
  40. package/types/taro.component.d.ts +2 -1
  41. package/types/taro.config.d.ts +91 -2
  42. package/types/taro.extend.d.ts +0 -112
@@ -0,0 +1,198 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ interface CacheManager {
5
+ /** 添加规则
6
+ * @supported weapp
7
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.addRule.html
8
+ */
9
+ addRule(option: CacheManager.AddRuleOption): string
10
+ /** 批量添加规则
11
+ * @supported weapp
12
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.addRules.html
13
+ */
14
+ addRules(option: CacheManager.AddRulesOption): string[]
15
+ /** 清空所有缓存
16
+ * @supported weapp
17
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.clearCaches.html
18
+ */
19
+ clearCaches(): void
20
+ /** 清空所有规则,同时会删除对应规则下所有缓存
21
+ * @supported weapp
22
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.clearRules.html
23
+ */
24
+ clearRules(): void
25
+ /** 删除缓存
26
+ * @supported weapp
27
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteCache.html
28
+ */
29
+ deleteCache(
30
+ /** 缓存 id */
31
+ id: string
32
+ ): void
33
+ /** 批量删除缓存
34
+ * @supported weapp
35
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteCaches.html
36
+ */
37
+ deleteCaches(
38
+ /** 缓存 id 列表 */
39
+ ids: string[]
40
+ ): void
41
+ /** 删除规则,同时会删除对应规则下所有缓存
42
+ * @supported weapp
43
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteRule.html
44
+ */
45
+ deleteRule(
46
+ /** 规则 id */
47
+ id: string
48
+ ): void
49
+ /** 批量删除规则,同时会删除对应规则下所有缓存
50
+ * @supported weapp
51
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteRules.html
52
+ */
53
+ deleteRules(
54
+ /** 规则 id 列表 */
55
+ ids: string[]
56
+ ): void
57
+ /** 匹配命中的缓存规则,一般需要和 request 事件搭配使用
58
+ * @supported weapp
59
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.match.html
60
+ */
61
+ match(option: CacheManager.MatchOption): CacheManager.MatchResult
62
+ /** 取消事件监听
63
+ * @supported weapp
64
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.off.html
65
+ */
66
+ off(
67
+ /** 事件名称 */
68
+ eventName: string,
69
+ /** 事件监听函数 */
70
+ handler: Function
71
+ ): void
72
+ /** 监听事件
73
+ * @supported weapp
74
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.on.html
75
+ */
76
+ on(
77
+ /** 事件名称 */
78
+ eventName: keyof CacheManager.OnEventName,
79
+ /** 事件监听函数 */
80
+ handler: Function
81
+ ): void
82
+ /** 开启缓存,仅在 mode 为 none 时生效,调用后缓存管理器的 state 会置为 1
83
+ * @supported weapp
84
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.start.html
85
+ */
86
+ start(): void
87
+ /** 关闭缓存,仅在 mode 为 none 时生效,调用后缓存管理器的 state 会置为 0
88
+ * @supported weapp
89
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.stop.html
90
+ */
91
+ stop(): void
92
+ }
93
+
94
+ namespace CacheManager {
95
+ interface DataSchema {
96
+ /** 需要匹配的 data 对象的参数类型
97
+ * string、number、boolean、null、object、any(表示任意类型),
98
+ * 同时支持数组模式(数组模式则在类型后面加 [],如 string[] 表示字符串数组)
99
+ */
100
+ type: string
101
+ /** 需要匹配的 data 对象的参数值
102
+ * 当 type 为基本类型时,可以用 string/regexp 来匹配固定的值,
103
+ * 也可以通过 function 来确定值是否匹配,
104
+ * 如果传入的 type 是 object,那么表示需要嵌套匹配值是否正确,可以传入 Array
105
+ */
106
+ value?: string | RegExp | Function | DataRule[]
107
+ }
108
+ interface DataRule {
109
+ /** 需要匹配的参数名 */
110
+ name: string
111
+ schema: DataSchema | DataSchema[]
112
+ }
113
+ interface RuleObject {
114
+ /** 规则 id,如果不填则会由基础库生成 */
115
+ id: string
116
+ /** 请求方法,可选值 GET/POST/PATCH/PUT/DELETE,如果为空则表示前面提到的所有方法都能被匹配到 */
117
+ method: string
118
+ /** uri 匹配规则,可参考规则字符串写法和正则写法 */
119
+ url: any
120
+ /**
121
+ * 缓存有效时间,单位为 ms,不填则默认取缓存管理器全局的缓存有效时间
122
+ * @default 7 * 24 * 60 * 60 * 1000
123
+ */
124
+ maxAge: number
125
+ /**
126
+ * 匹配请求参数
127
+ */
128
+ dataSchema: DataRule[]
129
+ }
130
+
131
+ type Rule = string | RegExp | RuleObject
132
+
133
+ interface AddRuleOption {
134
+ /** 规则 */
135
+ rule: Rule
136
+ }
137
+ interface AddRulesOption {
138
+ rules: Rule[]
139
+ }
140
+ interface MatchOption {
141
+ /** request 事件对象 */
142
+ evt: any
143
+ }
144
+ interface MatchResult {
145
+ /** 命中的规则id */
146
+ ruleId: string
147
+ /** 缓存id */
148
+ cacheId: string
149
+ /** 缓存内容,会带有 fromCache 标记,方便开发者区分内容是否来自缓存 */
150
+ data: any
151
+ /** 缓存创建时间 */
152
+ createTime: number
153
+ /** 缓存有效时间 */
154
+ maxAge: number
155
+ }
156
+ interface OnEventName {
157
+ /** 发生 wx.request 请求,只在缓存管理器开启阶段会触发 */
158
+ request
159
+ /** 进入弱网/离线状态 */
160
+ enterWeakNetwork
161
+ /** 离开弱网/离线状态 */
162
+ exitWeakNetwork
163
+ }
164
+ }
165
+
166
+ namespace createCacheManager {
167
+ interface Mode {
168
+ /** 弱网/离线使用缓存返回 */
169
+ weakNetwork
170
+ /** 总是使用缓存返回 */
171
+ always
172
+ /** 不开启,后续可手动开启/停止使用缓存返回 */
173
+ none
174
+ }
175
+ interface Extra {
176
+ /** 需要缓存的 wx api 接口,不传则表示支持缓存的接口全都做缓存处理。返回的如果是缓存数据,开发者可通过 fromCache 标记区分 */
177
+ apiList?: string[]
178
+ }
179
+ interface Option {
180
+ /** 全局 origin */
181
+ origin?: string
182
+ /** 缓存模式 */
183
+ mode?: keyof Mode
184
+ /** 全局缓存有效时间,单位为毫秒,默认为 7 天,最长不超过 30 天 */
185
+ maxAge?: number
186
+ /** 额外的缓存处理 */
187
+ extra?: Extra
188
+ }
189
+ }
190
+
191
+ interface TaroStatic {
192
+ /** 拉起手机发送短信界面
193
+ * @supported weap
194
+ * @see declare module '../../index'
195
+ */
196
+ createCacheManager(option: createCacheManager.Option): CacheManager
197
+ }
198
+ }
@@ -0,0 +1,223 @@
1
+ import React from 'react'
2
+
3
+ import Taro from '../index'
4
+
5
+ declare module '../index' {
6
+ namespace getAppInfo {
7
+ /** 应用信息 */
8
+ interface AppInfo {
9
+ platform: string
10
+ taroVersion: string
11
+ designWidth: number | ((size?: string | number) => number)
12
+ }
13
+ }
14
+
15
+ namespace getCurrentInstance {
16
+ interface Current {
17
+ app: AppInstance | null
18
+ router: RouterInfo | null
19
+ page: PageInstance | null
20
+ onReady: string
21
+ onHide: string
22
+ onShow: string
23
+ preloadData?: Record<any, any>
24
+ /**
25
+ * RN 私有对象navigationRef,用于使用底层接口控制路由
26
+ */
27
+ rnNavigationRef?: React.RefObject<any>
28
+ }
29
+ }
30
+
31
+ namespace setGlobalDataPlugin {
32
+ /** Vue3 插件,用于设置 `getApp()` 中的全局变量 */
33
+ interface Plugin {
34
+ install(app: any, data: any): void
35
+ }
36
+ }
37
+
38
+ /** @ignore */
39
+ interface TARO_ENV_TYPE {
40
+ [TaroGeneral.ENV_TYPE.WEAPP]: TaroGeneral.ENV_TYPE.WEAPP
41
+ [TaroGeneral.ENV_TYPE.WEB]: TaroGeneral.ENV_TYPE.WEB
42
+ [TaroGeneral.ENV_TYPE.RN]: TaroGeneral.ENV_TYPE.RN
43
+ [TaroGeneral.ENV_TYPE.SWAN]: TaroGeneral.ENV_TYPE.SWAN
44
+ [TaroGeneral.ENV_TYPE.ALIPAY]: TaroGeneral.ENV_TYPE.ALIPAY
45
+ [TaroGeneral.ENV_TYPE.TT]: TaroGeneral.ENV_TYPE.TT
46
+ [TaroGeneral.ENV_TYPE.QQ]: TaroGeneral.ENV_TYPE.QQ
47
+ [TaroGeneral.ENV_TYPE.JD]: TaroGeneral.ENV_TYPE.JD
48
+ }
49
+
50
+ namespace interceptorify {
51
+ type promiseifyApi<T, R> = (requestParams: T) => Promise<R>
52
+ interface InterceptorifyChain<T, R> {
53
+ requestParams: T
54
+ proceed: promiseifyApi<T, R>
55
+ }
56
+ type InterceptorifyInterceptor<T, R> = (chain: InterceptorifyChain<T, R>) => Promise<R>
57
+ interface Interceptorify<T, R> {
58
+ request(requestParams: T): Promise<R>
59
+ addInterceptor(interceptor: InterceptorifyInterceptor<T, R>): void
60
+ cleanInterceptors(): void
61
+ }
62
+ }
63
+
64
+ interface TaroStatic {
65
+ /** @ignore */
66
+ Events: {
67
+ new (): TaroGeneral.Events
68
+ }
69
+
70
+ /** 事件中心
71
+ * @supported global
72
+ */
73
+ eventCenter: TaroGeneral.Events
74
+
75
+ /** @ignore */
76
+ ENV_TYPE: TARO_ENV_TYPE
77
+
78
+ /** 获取环境变量
79
+ * @supported global
80
+ */
81
+ getEnv(): TaroGeneral.ENV_TYPE
82
+
83
+ /** 尺寸转换
84
+ * @supported global
85
+ */
86
+ pxTransform(size: number, designWidth?: number): string
87
+
88
+ /** 尺寸转换初始化
89
+ * @supported global
90
+ */
91
+ initPxTransform(config: {
92
+ baseFontSize?: number
93
+ deviceRatio?: TaroGeneral.TDeviceRatio
94
+ designWidth?: number | ((size?: string | number) => number)
95
+ targetUnit?: string
96
+ unitPrecision?: number
97
+ }): void
98
+
99
+ /** 小程序获取和 Taro 相关的 App 信息
100
+ * @supported weapp, alipay, jd, qq, swan, tt, h5
101
+ */
102
+ getAppInfo(): getAppInfo.AppInfo
103
+
104
+ getEnvInfoSync(): {
105
+ /** 小程序信息 */
106
+ microapp: {
107
+ /** 小程序版本号 */
108
+ mpVersion: string
109
+ /** 小程序环境 */
110
+ envType: string
111
+ /** 小程序appId */
112
+ appId: string
113
+ }
114
+ /** 插件信息 */
115
+ plugin: Record<string, unknown>
116
+ /** 通用参数 */
117
+ common: {
118
+ /** 用户数据存储的路径 */
119
+ USER_DATA_PATH: string
120
+ /** 校验白名单属性中的appInfoLaunchFrom后返回额外信息 */
121
+ location: string | undefined
122
+ launchFrom: string | undefined
123
+ schema: string | undefined
124
+ }
125
+ }
126
+
127
+ /** 小程序引用插件 JS 接口
128
+ * @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
129
+ */
130
+ requirePlugin(pluginName: string): any
131
+
132
+ /** 获取当前页面实例
133
+ * @supported global
134
+ */
135
+ getCurrentInstance(): getCurrentInstance.Current
136
+
137
+ /** @ignore */
138
+ Current: getCurrentInstance.Current
139
+
140
+ /** Vue3 插件,用于设置 `getApp()` 中的全局变量
141
+ * @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
142
+ * @example
143
+ * ```js
144
+ * // 使用插件
145
+ * const App = createApp(...)
146
+ * App.use(setGlobalDataPlugin, {
147
+ * xxx: 999
148
+ * })
149
+ * // 获取全局变量
150
+ * Taro.getApp().xxx
151
+ * ```
152
+ */
153
+ setGlobalDataPlugin: setGlobalDataPlugin.Plugin
154
+
155
+ /** 获取自定义 TabBar 对应的 React 或 Vue 组件实例
156
+ * @supported weapp, jd
157
+ * @param page 小程序页面对象,可以通过 Taro.getCurrentInstance().page 获取
158
+ */
159
+ getTabBar<T>(page: getCurrentInstance.Current['page']): T | undefined
160
+
161
+ /** 获取当前页面渲染引擎类型
162
+ * @supported weapp
163
+ */
164
+ getRenderer(): 'webview' | 'skyline'
165
+
166
+ /**
167
+ * 包裹 promiseify api 的洋葱圈模型
168
+ * @supported global
169
+ * @param promiseifyApi
170
+ * @example
171
+ * ```tsx
172
+ * // 创建实例
173
+ * const modalInterceptorify = interceptorify(taro.showModal)
174
+ * // 添加拦截器
175
+ * modalInterceptorify.addInterceptor(async function (chain) {
176
+ * const res = await chain.proceed({
177
+ * ...chain.requestParams,
178
+ * title: 'interceptor1'
179
+ * })
180
+ * return res
181
+ * })
182
+ * modalInterceptorify.addInterceptor(async function (chain) {
183
+ * const res = await chain.proceed({
184
+ * ...chain.requestParams,
185
+ * content: 'interceptor2'
186
+ * })
187
+ * return res
188
+ * })
189
+ * // 使用
190
+ * modalInterceptorify.request({})
191
+ * ```
192
+ * @example
193
+ * ```tsx
194
+ * // 创建实例
195
+ * const fetchDataInterceptorify = interceptorify(taro.request)
196
+ * // 添加拦截器
197
+ * fetchDataInterceptorify.addInterceptor(async function (chain) {
198
+ * taro.showLoading({
199
+ * title: 'Loading...'
200
+ * })
201
+ * const res = await chain.proceed(chain.requestParams)
202
+ * taro.hideLoading()
203
+ * return res
204
+ * })
205
+ * fetchDataInterceptorify.addInterceptor(async function (chain) {
206
+ * const params = chain.requestParams
207
+ * const res = await chain.proceed({
208
+ * url: 'http://httpbin.org' + params.url,
209
+ * })
210
+ * return res.data
211
+ * })
212
+ * // 使用
213
+ * fetchDataInterceptorify.request({
214
+ * url: '/ip'
215
+ * }).then((res) => {
216
+ * // log my ip
217
+ * console.log(res.origin)
218
+ * })
219
+ * ```
220
+ */
221
+ interceptorify<T, R>(promiseifyApi: interceptorify.promiseifyApi<T, R>): interceptorify.Interceptorify<T, R>
222
+ }
223
+ }
@@ -1,6 +1,6 @@
1
- import Taro from './index'
1
+ import Taro from '../index'
2
2
 
3
- declare module './index' {
3
+ declare module '../index' {
4
4
  interface TaroStatic {
5
5
  /**
6
6
  * 页面展示时的回调。
@@ -46,7 +46,7 @@ declare module './index' {
46
46
 
47
47
  /**
48
48
  * 当前是 tab 页时,tab 被点击时的回调。
49
- * @supported weapp, rn
49
+ * @supported weapp, h5, rn
50
50
  */
51
51
  useTabItemTap(callback: (payload: TabItemTapObject) => void): void
52
52
 
@@ -85,7 +85,7 @@ declare module './index' {
85
85
 
86
86
  /**
87
87
  * 小程序有未处理的 Promise reject 时触发。也可以使用 Taro.onUnhandledRejection 绑定监听。
88
- * @supported weapp, alipay
88
+ * @supported weapp, alipay, h5
89
89
  */
90
90
  useUnhandledRejection(callback: (error: { reason: Error, promise: Promise<Error> }) => void): void
91
91
 
@@ -85,7 +85,7 @@ declare module '../../index' {
85
85
  showNavigationBarLoading(option?: showNavigationBarLoading.Option): void
86
86
 
87
87
  /** 动态设置当前页面的标题
88
- * @supported weapp, h5, rn, tt
88
+ * @supported weapp, alipay, h5, rn, tt
89
89
  * @example
90
90
  * ```tsx
91
91
  * Taro.setNavigationBarTitle({
@@ -1,4 +1,4 @@
1
- import type swc from '@swc/core'
1
+ import type { swc } from '@tarojs/helper'
2
2
  import type Webpack from 'webpack'
3
3
 
4
4
  type CompilerTypes = 'webpack4' | 'webpack5' | 'vite'
@@ -5,8 +5,11 @@ import type HtmlWebpackPlugin from 'html-webpack-plugin'
5
5
  import type { IOption, IPostcssOption } from './util'
6
6
 
7
7
  export interface IH5RouterConfig {
8
+ /** 配置路由模式 */
8
9
  mode?: 'hash' | 'browser' | 'multi'
10
+ /** 配置自定义路由 */
9
11
  customRoutes?: IOption
12
+ /** 配置路由基准路径 */
10
13
  basename?: string
11
14
  lazyload?: boolean | ((pagename: string) => boolean)
12
15
  renamePagename?: (pagename: string) => string
@@ -14,37 +17,95 @@ export interface IH5RouterConfig {
14
17
  }
15
18
 
16
19
  export interface IH5Config {
20
+ /** 设置输出解析文件的目录(默认值:'/')*/
17
21
  publicPath?: string
22
+
23
+ /** h5 编译后的静态文件目录(默认值:'static') */
18
24
  staticDirectory?: string
25
+
26
+ /** 编译后非 entry 的 js 文件的存放目录,主要影响动态引入的 pages 的存放路径(默认值:'chunk') */
19
27
  chunkDirectory?: string
20
28
 
21
29
  webpack?: ((webpackConfig: Webpack.Configuration, webpack) => Webpack.Configuration) | Webpack.Configuration
22
30
 
31
+ /**
32
+ * 自定义 Webpack 配置
33
+ * @param chain [webpackChain](https://github.com/neutrinojs/webpack-chain) 对象
34
+ * @param webpack webpack 实例
35
+ */
23
36
  webpackChain?: (chain: Chain, webpack: typeof Webpack) => void
24
37
 
38
+ /** 可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/) */
25
39
  output?: Webpack.Configuration['output']
40
+
41
+ /** 路由相关的配置 */
26
42
  router?: IH5RouterConfig
43
+
44
+ /** 预览服务的配置,可以更改端口等参数。具体配置参考 [webpack-dev-server](https://webpack.js.org/configuration/dev-server) */
27
45
  devServer?: webpackDevServer.Configuration
28
- sourceMapType?: 'none' | 'eval' | 'cheap-eval-source-map' | 'cheap-module-eval-source-map' | 'eval-source-map' | 'cheap-source-map' | 'cheap-module-source-map' | 'inline-cheap-source-map' | 'inline-cheap-module-source-map' | 'source-map' | 'inline-source-map' | 'hidden-source-map' | 'nosources-source-map'
46
+
47
+ /** 具体配置请参考 [Webpack devtool](https://webpack.js.org/configuration/devtool/#devtool) 配置 (默认值:'cheap-module-eval-source-map')*/
48
+ sourceMapType?:
49
+ | 'none'
50
+ | 'eval'
51
+ | 'cheap-eval-source-map'
52
+ | 'cheap-module-eval-source-map'
53
+ | 'eval-source-map'
54
+ | 'cheap-source-map'
55
+ | 'cheap-module-source-map'
56
+ | 'inline-cheap-source-map'
57
+ | 'inline-cheap-module-source-map'
58
+ | 'source-map'
59
+ | 'inline-source-map'
60
+ | 'hidden-source-map'
61
+ | 'nosources-source-map'
62
+
63
+ /** extract 功能开关,开启后将使用 mini-css-extract-plugin 分离 css 文件,可通过 h5.miniCssExtractPluginOption 对插件进行配置 (默认值:watch 模式下为 false,否则为 true) */
29
64
  enableExtract?: boolean
30
- transformOnly?: boolean
31
65
 
66
+ /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
32
67
  cssLoaderOption?: IOption
68
+
69
+ /** [style-loader](https://github.com/webpack-contrib/style-loader) 的附加配置 */
33
70
  styleLoaderOption?: IOption
71
+
72
+ /** [sass-loader](https://github.com/webpack-contrib/sass-loader) 的附加配置 */
34
73
  sassLoaderOption?: IOption
74
+
75
+ /** [less-loader](https://github.com/webpack-contrib/less-loader) 的附加配置 */
35
76
  lessLoaderOption?: IOption
77
+
78
+ /** [stylus-loader](https://github.com/shama/stylus-loader) 的附加配置 */
36
79
  stylusLoaderOption?: IOption
80
+
81
+ /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
37
82
  mediaUrlLoaderOption?: IOption
83
+
84
+ /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
38
85
  fontUrlLoaderOption?: IOption
86
+
87
+ /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
39
88
  imageUrlLoaderOption?: IOption
89
+
90
+ /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
40
91
  miniCssExtractPluginOption?: IOption
92
+
93
+ /** 配置需要额外的经由 Taro 预设的 postcss 编译的模块 */
41
94
  esnextModules?: string[]
95
+
96
+ /** 用于控制在 H5 端是否使用兼容性组件库,详情请看 [React 兼容性组件库](https://taro-docs.jd.com/docs/next/h5#react-兼容性组件库)。(默认值:false) */
42
97
  useHtmlComponents?: boolean
98
+
99
+ /** 用于控制在 H5 端是否使用旧版本适配器,旧版本采用全局注册组件,懒加载组件相关依赖;新版本适配器会自动注册相关组件,不再需要引入 @tarojs/components/loader 中的全局 defineCustomElements 方法。(默认值:false) */
43
100
  useDeprecatedAdapterComponent?: boolean
44
101
 
102
+ /** 配置 postcss 相关插件 */
45
103
  postcss?: IPostcssOption
104
+
105
+ /** html-webpack-plugin 的具体配置 */
46
106
  htmlPluginOption?: HtmlWebpackPlugin.Options
47
107
 
108
+ /** Web 编译过程的相关配置 */
48
109
  compile?: {
49
110
  exclude?: any[]
50
111
  include?: any[]
@@ -1,6 +1,6 @@
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 } from './util'
4
4
 
5
5
  interface Runtime {
6
6
  enableInnerHTML: boolean
@@ -13,36 +13,98 @@ interface Runtime {
13
13
  }
14
14
 
15
15
  export interface IMiniAppConfig {
16
- appOutput?: boolean
16
+ /** 默认值:'cheap-module-source-map', 具体参考[Webpack devtool 配置](https://webpack.js.org/configuration/devtool/#devtool) */
17
17
  sourceMapType?: string
18
+
19
+ /** 指定 React 框架相关的代码是否使用开发环境(未压缩)代码,默认使用生产环境(压缩后)代码 */
18
20
  debugReact?: boolean
21
+
22
+ /** 是否跳过第三方依赖 usingComponent 的处理,默认为自动处理第三方依赖的自定义组件 */
23
+ skipProcessUsingComponents?: boolean
24
+
25
+ /** 压缩小程序 xml 文件的相关配置 */
19
26
  minifyXML?: {
27
+ /** 是否合并 xml 文件中的空格 (默认false) */
20
28
  collapseWhitespace?: boolean
21
29
  }
22
30
 
31
+ /**
32
+ * 自定义 Webpack 配置
33
+ * @param chain [webpackChain](https://github.com/neutrinojs/webpack-chain) 对象
34
+ * @param webpack webpack 实例
35
+ * @param PARSE_AST_TYPE 小程序编译时的文件类型集合
36
+ * @returns
37
+ */
23
38
  webpackChain?: (chain: Chain, webpack: typeof Webpack, PARSE_AST_TYPE: any) => void
24
- output?: Webpack.Configuration['output']
39
+
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
+ }
55
+
56
+ /** 配置 postcss 相关插件 */
25
57
  postcss?: IPostcssOption
58
+
59
+ /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
26
60
  cssLoaderOption?: IOption
61
+
62
+ /** [sass-loader](https://github.com/webpack-contrib/sass-loader) 的附加配置 */
27
63
  sassLoaderOption?: IOption
64
+
65
+ /** [less-loader](https://github.com/webpack-contrib/less-loader) 的附加配置 */
28
66
  lessLoaderOption?: IOption
67
+
68
+ /** [stylus-loader](https://github.com/shama/stylus-loader) 的附加配置 */
29
69
  stylusLoaderOption?: IOption
70
+
71
+ /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
30
72
  mediaUrlLoaderOption?: IOption
73
+
74
+ /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
31
75
  fontUrlLoaderOption?: IOption
76
+
77
+ /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
32
78
  imageUrlLoaderOption?: IOption
79
+
80
+ /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
33
81
  miniCssExtractPluginOption?: IOption
34
82
 
35
- customFilesTypes?: IMINI_APP_FILE_TYPE
83
+ /** 用于告诉 Taro 编译器需要抽取的公共文件 */
36
84
  commonChunks?: string[] | ((commonChunks: string[]) => string[])
37
- addChunkPages?: ((pages: Map<string, string[]>, pagesNames?: string[]) => void)
85
+
86
+ /** 为某些页面单独指定需要引用的公共文件 */
87
+ addChunkPages?: (pages: Map<string, string[]>, pagesNames?: string[]) => void
88
+
89
+ /** 优化主包的体积大小 */
38
90
  optimizeMainPackage?: {
39
91
  enable?: boolean
40
92
  exclude?: any[]
41
93
  }
42
94
 
95
+ /** 小程序编译过程的相关配置 */
43
96
  compile?: {
44
97
  exclude?: any[]
45
98
  include?: any[]
46
99
  }
100
+
101
+ /** 插件内部使用 */
47
102
  runtime?: Runtime
48
103
  }
104
+
105
+ export interface IMiniFilesConfig {
106
+ [configName: string]: {
107
+ content: Config
108
+ path: string
109
+ }
110
+ }