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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/package.json +16 -3
  2. package/types/api/ad/index.d.ts +6 -18
  3. package/types/api/ai/inference.d.ts +129 -0
  4. package/types/api/ai/visionkit.d.ts +625 -54
  5. package/types/api/alipay/index.d.ts +43 -0
  6. package/types/api/base/crypto.d.ts +18 -4
  7. package/types/api/base/index.d.ts +2 -2
  8. package/types/api/base/performance.d.ts +65 -2
  9. package/types/api/base/system.d.ts +65 -0
  10. package/types/api/base/weapp/app-event.d.ts +18 -18
  11. package/types/api/canvas/index.d.ts +67 -54
  12. package/types/api/device/calendar.d.ts +2 -2
  13. package/types/api/device/screen.d.ts +61 -0
  14. package/types/api/device/sms.d.ts +26 -0
  15. package/types/api/media/audio.d.ts +50 -30
  16. package/types/api/media/image.d.ts +40 -17
  17. package/types/api/media/live.d.ts +52 -0
  18. package/types/api/media/video.d.ts +64 -23
  19. package/types/api/media/voip.d.ts +103 -0
  20. package/types/api/network/download.d.ts +2 -10
  21. package/types/api/network/request.d.ts +84 -24
  22. package/types/api/network/upload.d.ts +2 -10
  23. package/types/api/open-api/address.d.ts +12 -10
  24. package/types/api/open-api/channels.d.ts +31 -0
  25. package/types/api/open-api/device-voip.d.ts +63 -0
  26. package/types/api/open-api/login.d.ts +1 -1
  27. package/types/api/open-api/my-miniprogram.d.ts +2 -2
  28. package/types/api/open-api/privacy.d.ts +99 -0
  29. package/types/api/route/index.d.ts +3 -0
  30. package/types/api/share/index.d.ts +1 -1
  31. package/types/api/skyline/index.d.ts +59 -0
  32. package/types/api/storage/cache-manager.d.ts +198 -0
  33. package/types/api/taro.extend.d.ts +223 -0
  34. package/types/{taro.hooks.d.ts → api/taro.hooks.d.ts} +4 -4
  35. package/types/api/ui/navigation-bar.d.ts +1 -1
  36. package/types/compile/compiler.d.ts +8 -6
  37. package/types/compile/config/h5.d.ts +79 -11
  38. package/types/compile/config/mini.d.ts +83 -12
  39. package/types/compile/config/project.d.ts +242 -20
  40. package/types/compile/config/rn.d.ts +64 -0
  41. package/types/compile/config/util.d.ts +83 -11
  42. package/types/compile/hooks.d.ts +1 -1
  43. package/types/compile/viteCompilerContext.d.ts +128 -0
  44. package/types/global.d.ts +9 -8
  45. package/types/index.d.ts +9 -7
  46. package/types/taro.api.d.ts +11 -1
  47. package/types/taro.component.d.ts +3 -2
  48. package/types/taro.config.d.ts +122 -2
  49. package/types/taro.extend.d.ts +0 -112
@@ -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: TaroGeneral.EventCallback
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: TaroGeneral.EventCallback
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 weapp
194
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/wx.createCacheManager.html
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): 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,7 +1,9 @@
1
- import type swc from '@swc/core'
1
+ import type { swc } from '@tarojs/helper'
2
2
  import type Webpack from 'webpack'
3
3
 
4
- type CompilerTypes = 'webpack4' | 'webpack5' | 'vite'
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: CompilerTypes
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 = CompilerTypes | ICompiler
28
+ export type Compiler<T extends CompilerTypes = CompilerWebpackTypes> = T | ICompiler<T>
@@ -2,51 +2,119 @@ 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 {
10
+ /** 配置路由模式 */
8
11
  mode?: 'hash' | 'browser' | 'multi'
12
+ /** 配置自定义路由 */
9
13
  customRoutes?: IOption
14
+ /** 配置路由基准路径 */
10
15
  basename?: string
11
16
  lazyload?: boolean | ((pagename: string) => boolean)
12
17
  renamePagename?: (pagename: string) => string
13
18
  forcePath?: string
14
19
  }
15
20
 
16
- export interface IH5Config {
21
+ export interface IH5Config <T extends CompilerTypes = CompilerWebpackTypes> {
22
+ /** 设置输出解析文件的目录(默认值:'/')*/
17
23
  publicPath?: string
24
+
25
+ /** h5 编译后的静态文件目录(默认值:'static') */
18
26
  staticDirectory?: string
27
+
28
+ /** 编译后非 entry 的 js 文件的存放目录,主要影响动态引入的 pages 的存放路径(默认值:'chunk') */
19
29
  chunkDirectory?: string
20
30
 
21
31
  webpack?: ((webpackConfig: Webpack.Configuration, webpack) => Webpack.Configuration) | Webpack.Configuration
22
32
 
33
+ /**
34
+ * 自定义 Webpack 配置
35
+ * @param chain [webpackChain](https://github.com/neutrinojs/webpack-chain) 对象
36
+ * @param webpack webpack 实例
37
+ */
23
38
  webpackChain?: (chain: Chain, webpack: typeof Webpack) => void
24
39
 
25
- 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']
44
+
45
+ /** 路由相关的配置 */
26
46
  router?: IH5RouterConfig
47
+
48
+ /** 预览服务的配置,可以更改端口等参数。具体配置参考 [webpack-dev-server](https://webpack.js.org/configuration/dev-server) */
27
49
  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'
50
+
51
+ /** 具体配置请参考 [Webpack devtool](https://webpack.js.org/configuration/devtool/#devtool) 配置 (默认值:'cheap-module-eval-source-map')*/
52
+ sourceMapType?:
53
+ | 'none'
54
+ | 'eval'
55
+ | 'cheap-eval-source-map'
56
+ | 'cheap-module-eval-source-map'
57
+ | 'eval-source-map'
58
+ | 'cheap-source-map'
59
+ | 'cheap-module-source-map'
60
+ | 'inline-cheap-source-map'
61
+ | 'inline-cheap-module-source-map'
62
+ | 'source-map'
63
+ | 'inline-source-map'
64
+ | 'hidden-source-map'
65
+ | 'nosources-source-map'
66
+
67
+ /** extract 功能开关,开启后将使用 mini-css-extract-plugin 分离 css 文件,可通过 h5.miniCssExtractPluginOption 对插件进行配置 (默认值:watch 模式下为 false,否则为 true) */
29
68
  enableExtract?: boolean
30
- transformOnly?: boolean
31
69
 
70
+ /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
32
71
  cssLoaderOption?: IOption
72
+
73
+ /** [style-loader](https://github.com/webpack-contrib/style-loader) 的附加配置 */
33
74
  styleLoaderOption?: IOption
75
+
76
+ /** [sass-loader](https://github.com/webpack-contrib/sass-loader) 的附加配置 */
34
77
  sassLoaderOption?: IOption
78
+
79
+ /** [less-loader](https://github.com/webpack-contrib/less-loader) 的附加配置 */
35
80
  lessLoaderOption?: IOption
81
+
82
+ /** [stylus-loader](https://github.com/shama/stylus-loader) 的附加配置 */
36
83
  stylusLoaderOption?: IOption
37
- mediaUrlLoaderOption?: IOption
38
- fontUrlLoaderOption?: IOption
39
- imageUrlLoaderOption?: IOption
84
+
85
+ /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
86
+ mediaUrlLoaderOption?: IUrlLoaderOption
87
+
88
+ /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
89
+ fontUrlLoaderOption?: IUrlLoaderOption
90
+
91
+ /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
92
+ imageUrlLoaderOption?: IUrlLoaderOption
93
+
94
+ /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
40
95
  miniCssExtractPluginOption?: IOption
96
+
97
+ /** 配置需要额外的经由 Taro 预设的 postcss 编译的模块 */
41
98
  esnextModules?: string[]
99
+
100
+ /** 用于控制在 H5 端是否使用兼容性组件库,详情请看 [React 兼容性组件库](https://taro-docs.jd.com/docs/next/h5#react-兼容性组件库)。(默认值:false) */
42
101
  useHtmlComponents?: boolean
102
+
103
+ /** 用于控制在 H5 端是否使用旧版本适配器,旧版本采用全局注册组件,懒加载组件相关依赖;新版本适配器会自动注册相关组件,不再需要引入 @tarojs/components/loader 中的全局 defineCustomElements 方法。(默认值:false) */
43
104
  useDeprecatedAdapterComponent?: boolean
44
105
 
45
- postcss?: IPostcssOption
106
+ /** 配置 postcss 相关插件 */
107
+ postcss?: IPostcssOption<'H5'>
108
+
109
+ /** html-webpack-plugin 的具体配置 */
46
110
  htmlPluginOption?: HtmlWebpackPlugin.Options
47
111
 
112
+ /** Web 编译过程的相关配置 */
48
113
  compile?: {
49
- exclude?: any[]
50
- include?: any[]
114
+ exclude?: (string | RegExp)[]
115
+ include?: (string | RegExp)[]
116
+ filter?: (filename: string) => boolean
51
117
  }
118
+ /** 是否把代码转化为 es5,只在 vite 编译模式下有效 */
119
+ es5?: T extends 'vite' ? boolean : undefined
52
120
  }