@tarojs/taro 4.0.1 → 4.0.3-alpha.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.
- package/package.json +40 -16
- package/types/api/base/env.d.ts +1 -1
- package/types/api/base/system.d.ts +2 -2
- package/types/api/base/weapp/app-event.d.ts +4 -4
- package/types/api/device/accelerometer.d.ts +4 -4
- package/types/api/device/battery.d.ts +2 -2
- package/types/api/device/clipboard.d.ts +14 -14
- package/types/api/device/keyboard.d.ts +2 -2
- package/types/api/device/network.d.ts +3 -3
- package/types/api/device/phone.d.ts +1 -1
- package/types/api/device/screen.d.ts +2 -2
- package/types/api/device/vibrate.d.ts +2 -2
- package/types/api/media/image.d.ts +2 -2
- package/types/api/network/request.d.ts +1 -1
- package/types/api/route/index.d.ts +5 -5
- package/types/api/storage/index.d.ts +4 -4
- package/types/api/swan/pay.d.ts +4 -4
- package/types/api/taro.extend.d.ts +5 -3
- package/types/api/ui/animation.d.ts +1 -1
- package/types/api/ui/interaction.d.ts +3 -3
- package/types/api/ui/navigation-bar.d.ts +5 -5
- package/types/api/ui/pull-down-refresh.d.ts +2 -2
- package/types/api/ui/scroll.d.ts +1 -1
- package/types/api/ui/tab-bar.d.ts +7 -7
- package/types/api/wxml/index.d.ts +15 -9
- package/types/compile/compiler.d.ts +9 -4
- package/types/compile/config/h5.d.ts +23 -10
- package/types/compile/config/harmony.d.ts +118 -0
- package/types/compile/config/index.d.ts +1 -0
- package/types/compile/config/mini.d.ts +29 -24
- package/types/compile/config/plugin.d.ts +34 -0
- package/types/compile/config/project.d.ts +49 -21
- package/types/compile/config/util.d.ts +21 -7
- package/types/compile/index.d.ts +8 -0
- package/types/compile/viteCompilerContext.d.ts +159 -0
- package/types/index.d.ts +0 -1
- package/types/taro.component.d.ts +1 -0
- package/types/taro.config.d.ts +5 -0
|
@@ -121,13 +121,13 @@ declare module '../../index' {
|
|
|
121
121
|
|
|
122
122
|
interface TaroStatic {
|
|
123
123
|
/** 显示 tabBar 某一项的右上角的红点
|
|
124
|
-
* @supported weapp, h5, rn, tt, harmony_hybrid
|
|
124
|
+
* @supported weapp, h5, rn, tt, harmony, harmony_hybrid
|
|
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, harmony_hybrid
|
|
130
|
+
* @supported weapp, h5, rn, tt, harmony, harmony_hybrid
|
|
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, harmony_hybrid
|
|
151
|
+
* @supported weapp, h5, rn, tt, harmony, harmony_hybrid
|
|
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, harmony_hybrid
|
|
166
|
+
* @supported weapp, h5, rn, tt, harmony, harmony_hybrid
|
|
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, harmony_hybrid
|
|
179
|
+
* @supported weapp, h5, rn, tt, harmony, harmony_hybrid
|
|
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, harmony_hybrid
|
|
185
|
+
* @supported weapp, h5, rn, tt, harmony, harmony_hybrid
|
|
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, harmony_hybrid
|
|
191
|
+
* @supported weapp, h5, rn, tt, harmony, harmony_hybrid
|
|
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>
|
|
@@ -66,19 +66,25 @@ declare module '../../index' {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
namespace IntersectionObserver {
|
|
69
|
-
/** 监听相交状态变化的回调函数
|
|
69
|
+
/** 监听相交状态变化的回调函数
|
|
70
|
+
* @description Harmony 找不到对应元素时,回调会返回一个 Error 对象
|
|
71
|
+
*/
|
|
70
72
|
type ObserveCallback = (result: ObserveCallbackResult) => void
|
|
71
|
-
interface ObserveCallbackResult {
|
|
73
|
+
interface ObserveCallbackResult extends TaroGeneral.CallbackResult {
|
|
74
|
+
/** 错误信息,会在找不到对应元素时返回
|
|
75
|
+
* @supported harmony
|
|
76
|
+
*/
|
|
77
|
+
errMsg?: string
|
|
72
78
|
/** 目标边界 */
|
|
73
|
-
boundingClientRect
|
|
79
|
+
boundingClientRect?: BoundingClientRectResult
|
|
74
80
|
/** 相交比例 */
|
|
75
|
-
intersectionRatio
|
|
81
|
+
intersectionRatio?: number
|
|
76
82
|
/** 相交区域的边界 */
|
|
77
|
-
intersectionRect
|
|
83
|
+
intersectionRect?: IntersectionRectResult
|
|
78
84
|
/** 参照区域的边界 */
|
|
79
|
-
relativeRect
|
|
85
|
+
relativeRect?: RelativeRectResult
|
|
80
86
|
/** 相交检测时的时间戳 */
|
|
81
|
-
time
|
|
87
|
+
time?: number
|
|
82
88
|
}
|
|
83
89
|
/** 参照区域的边界 */
|
|
84
90
|
interface RelativeRectResult {
|
|
@@ -484,7 +490,7 @@ declare module '../../index' {
|
|
|
484
490
|
|
|
485
491
|
interface TaroStatic {
|
|
486
492
|
/** 返回一个 SelectorQuery 对象实例。在自定义组件或包含自定义组件的页面中,应使用 `this.createSelectorQuery()` 来代替。
|
|
487
|
-
* @supported weapp, h5, tt, harmony_hybrid
|
|
493
|
+
* @supported weapp, h5, tt, harmony, harmony_hybrid
|
|
488
494
|
* @example
|
|
489
495
|
* ```tsx
|
|
490
496
|
* const query = Taro.createSelectorQuery()
|
|
@@ -500,7 +506,7 @@ declare module '../../index' {
|
|
|
500
506
|
createSelectorQuery(): SelectorQuery
|
|
501
507
|
|
|
502
508
|
/** 创建并返回一个 IntersectionObserver 对象实例。在自定义组件或包含自定义组件的页面中,应使用 `this.createIntersectionObserver([options])` 来代替。
|
|
503
|
-
* @supported weapp, h5, tt, harmony_hybrid
|
|
509
|
+
* @supported weapp, h5, tt, harmony, harmony_hybrid
|
|
504
510
|
* @example
|
|
505
511
|
* ```tsx
|
|
506
512
|
* const observer = Taro.createIntersectionObserver(this, { thresholds: [0], observeAll: true })
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { swc } from '@tarojs/helper'
|
|
2
2
|
import type Webpack from 'webpack'
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
export type CompilerViteTypes = 'vite'
|
|
5
|
+
|
|
6
|
+
export type CompilerWebpackTypes = 'webpack5'
|
|
7
|
+
|
|
8
|
+
export type CompilerTypes = CompilerWebpackTypes | CompilerViteTypes
|
|
5
9
|
|
|
6
10
|
interface IPrebundle {
|
|
7
11
|
enable?: boolean
|
|
@@ -17,11 +21,12 @@ interface IPrebundle {
|
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
interface ICompiler {
|
|
21
|
-
type:
|
|
24
|
+
interface ICompiler<T> {
|
|
25
|
+
type: T
|
|
22
26
|
prebundle?: IPrebundle
|
|
27
|
+
vitePlugins?: any
|
|
23
28
|
/** 错误处理级别。可选值:0、1 */
|
|
24
29
|
errorLevel?: number
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
export type Compiler
|
|
32
|
+
export type Compiler<T extends CompilerTypes = CompilerWebpackTypes> = T | ICompiler<T>
|
|
@@ -2,7 +2,10 @@ 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'
|
|
8
|
+
import type { OutputExt } from './project'
|
|
6
9
|
|
|
7
10
|
export interface IH5RouterConfig {
|
|
8
11
|
/** 配置路由模式 */
|
|
@@ -18,7 +21,7 @@ export interface IH5RouterConfig {
|
|
|
18
21
|
enhanceAnimation?: boolean
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
export interface IH5Config {
|
|
24
|
+
export interface IH5Config <T extends CompilerTypes = CompilerWebpackTypes> {
|
|
22
25
|
/** 设置输出解析文件的目录(默认值:'/')*/
|
|
23
26
|
publicPath?: string
|
|
24
27
|
|
|
@@ -37,8 +40,12 @@ export interface IH5Config {
|
|
|
37
40
|
*/
|
|
38
41
|
webpackChain?: (chain: Chain, webpack: typeof Webpack) => void
|
|
39
42
|
|
|
40
|
-
/**
|
|
41
|
-
output
|
|
43
|
+
/** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/)
|
|
44
|
+
* vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/)
|
|
45
|
+
*/
|
|
46
|
+
output?: T extends 'vite'
|
|
47
|
+
? Pick<RollupOutputOptions, 'chunkFileNames' | 'assetFileNames'> & OutputExt
|
|
48
|
+
: Webpack.Configuration['output']
|
|
42
49
|
|
|
43
50
|
/** 路由相关的配置 */
|
|
44
51
|
router?: IH5RouterConfig
|
|
@@ -84,13 +91,13 @@ export interface IH5Config {
|
|
|
84
91
|
stylusLoaderOption?: IOption
|
|
85
92
|
|
|
86
93
|
/** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
87
|
-
mediaUrlLoaderOption?:
|
|
94
|
+
mediaUrlLoaderOption?: IUrlLoaderOption
|
|
88
95
|
|
|
89
96
|
/** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
90
|
-
fontUrlLoaderOption?:
|
|
97
|
+
fontUrlLoaderOption?: IUrlLoaderOption
|
|
91
98
|
|
|
92
99
|
/** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
93
|
-
imageUrlLoaderOption?:
|
|
100
|
+
imageUrlLoaderOption?: IUrlLoaderOption
|
|
94
101
|
|
|
95
102
|
/** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
|
|
96
103
|
miniCssExtractPluginOption?: IOption
|
|
@@ -105,14 +112,20 @@ export interface IH5Config {
|
|
|
105
112
|
useDeprecatedAdapterComponent?: boolean
|
|
106
113
|
|
|
107
114
|
/** 配置 postcss 相关插件 */
|
|
108
|
-
postcss?: IPostcssOption
|
|
115
|
+
postcss?: IPostcssOption<'h5'>
|
|
109
116
|
|
|
110
117
|
/** html-webpack-plugin 的具体配置 */
|
|
111
118
|
htmlPluginOption?: HtmlWebpackPlugin.Options
|
|
112
119
|
|
|
113
120
|
/** Web 编译过程的相关配置 */
|
|
114
121
|
compile?: {
|
|
115
|
-
exclude?:
|
|
116
|
-
include?:
|
|
122
|
+
exclude?: (string | RegExp)[]
|
|
123
|
+
include?: (string | RegExp)[]
|
|
124
|
+
filter?: (filename: string) => boolean
|
|
117
125
|
}
|
|
126
|
+
/** 生成的代码是否要兼容旧版浏览器,值为 true 时,会去读取 package.json 的 browserslist 字段。只在 vite 编译模式下有效 */
|
|
127
|
+
legacy?: T extends 'vite' ? boolean : undefined
|
|
128
|
+
|
|
129
|
+
/** 使用的编译工具。可选值:webpack5、vite */
|
|
130
|
+
compiler?: Compiler<T>
|
|
118
131
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { OutputOptions as RollupOutputOptions } from 'rollup'
|
|
2
|
+
import type Webpack from 'webpack'
|
|
3
|
+
import type Chain from 'webpack-chain'
|
|
4
|
+
|
|
5
|
+
import type { IOption, IPostcssOption, IUrlLoaderOption } from './util'
|
|
6
|
+
import type { CompilerTypes, CompilerWebpackTypes } from '../compiler'
|
|
7
|
+
import type { OutputExt } from './project'
|
|
8
|
+
|
|
9
|
+
export interface IHarmonyRouterConfig {
|
|
10
|
+
/** 配置自定义路由 */
|
|
11
|
+
customRoutes?: IOption
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface IHarmonyConfig<T extends CompilerTypes = 'vite'> {
|
|
15
|
+
/** Harmony 项目地址 */
|
|
16
|
+
projectPath: string
|
|
17
|
+
|
|
18
|
+
/** hap 名
|
|
19
|
+
* @default "entry"
|
|
20
|
+
*/
|
|
21
|
+
hapName?: string
|
|
22
|
+
|
|
23
|
+
/** 应用名称
|
|
24
|
+
* @default "default"
|
|
25
|
+
*/
|
|
26
|
+
name?: string
|
|
27
|
+
|
|
28
|
+
/** oh-package.json 配置 */
|
|
29
|
+
ohPackage?: {
|
|
30
|
+
dependencies?: { [name: string]: string }
|
|
31
|
+
devDependencies?: { [name: string]: string }
|
|
32
|
+
main?: string
|
|
33
|
+
[k: string]: any
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** ohpm-cli
|
|
37
|
+
* @default "~/Library/Huawei/ohpm/bin/ohpm"
|
|
38
|
+
*/
|
|
39
|
+
ohpm?: string
|
|
40
|
+
|
|
41
|
+
/** 核心依赖前缀
|
|
42
|
+
* @description 用于告诉编译内容如何解析核心依赖,传入时将直接使用依赖前缀,同时不会为工程导入核心依赖
|
|
43
|
+
*/
|
|
44
|
+
chorePackagePrefix?: string
|
|
45
|
+
|
|
46
|
+
/** 用于告诉 Taro 编译器需要抽取的公共文件 */
|
|
47
|
+
commonChunks?: string[] | ((commonChunks: string[]) => string[])
|
|
48
|
+
|
|
49
|
+
/** Harmony 编译过程的相关配置 */
|
|
50
|
+
compile?: {
|
|
51
|
+
exclude?: any[]
|
|
52
|
+
include?: any[]
|
|
53
|
+
filter?: (filename: string) => boolean
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 用于配置半编译模式下的选项 */
|
|
57
|
+
compileModeSetting?: {
|
|
58
|
+
componentReplace?: {
|
|
59
|
+
[key: string]: {
|
|
60
|
+
current_init: string
|
|
61
|
+
dependency_define: string
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 用于控制是否生成 js、css 对应的 sourceMap (默认值:watch 模式下为 true,否则为 false) */
|
|
67
|
+
enableSourceMap?: boolean
|
|
68
|
+
|
|
69
|
+
/** 默认值:'cheap-module-source-map', 具体参考[Webpack devtool 配置](https://webpack.js.org/configuration/devtool/#devtool) */
|
|
70
|
+
sourceMapType?: string
|
|
71
|
+
|
|
72
|
+
/** 指定 React 框架相关的代码是否使用开发环境(未压缩)代码,默认使用生产环境(压缩后)代码 */
|
|
73
|
+
debugReact?: boolean
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 自定义 Webpack 配置
|
|
77
|
+
* @param chain [webpackChain](https://github.com/neutrinojs/webpack-chain) 对象
|
|
78
|
+
* @param webpack webpack 实例
|
|
79
|
+
*/
|
|
80
|
+
webpackChain?: (chain: Chain, webpack: typeof Webpack) => void
|
|
81
|
+
|
|
82
|
+
/** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/)
|
|
83
|
+
* vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/)
|
|
84
|
+
*/
|
|
85
|
+
output?: T extends 'vite'
|
|
86
|
+
? Pick<RollupOutputOptions, 'chunkFileNames'> & OutputExt
|
|
87
|
+
: Webpack.Configuration['output'] & OutputExt
|
|
88
|
+
|
|
89
|
+
/** 路由相关的配置 */
|
|
90
|
+
router?: IHarmonyRouterConfig
|
|
91
|
+
|
|
92
|
+
/** 配置 postcss 相关插件 */
|
|
93
|
+
postcss?: IPostcssOption<'harmony'>
|
|
94
|
+
|
|
95
|
+
/** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
|
|
96
|
+
cssLoaderOption?: IOption
|
|
97
|
+
|
|
98
|
+
/** [sass-loader](https://github.com/webpack-contrib/sass-loader) 的附加配置 */
|
|
99
|
+
sassLoaderOption?: IOption
|
|
100
|
+
|
|
101
|
+
/** [less-loader](https://github.com/webpack-contrib/less-loader) 的附加配置 */
|
|
102
|
+
lessLoaderOption?: IOption
|
|
103
|
+
|
|
104
|
+
/** [stylus-loader](https://github.com/shama/stylus-loader) 的附加配置 */
|
|
105
|
+
stylusLoaderOption?: IOption
|
|
106
|
+
|
|
107
|
+
/** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
108
|
+
mediaUrlLoaderOption?: IUrlLoaderOption
|
|
109
|
+
|
|
110
|
+
/** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
111
|
+
fontUrlLoaderOption?: IUrlLoaderOption
|
|
112
|
+
|
|
113
|
+
/** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
114
|
+
imageUrlLoaderOption?: IUrlLoaderOption
|
|
115
|
+
|
|
116
|
+
/** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
|
|
117
|
+
miniCssExtractPluginOption?: IOption
|
|
118
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
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'
|
|
6
|
+
import type { OutputExt } from './project'
|
|
4
7
|
|
|
5
8
|
interface Runtime {
|
|
6
9
|
enableInnerHTML?: boolean
|
|
@@ -12,7 +15,7 @@ interface Runtime {
|
|
|
12
15
|
enableMutationObserver?: boolean
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
export interface IMiniAppConfig {
|
|
18
|
+
export interface IMiniAppConfig<T extends CompilerTypes = CompilerWebpackTypes> {
|
|
16
19
|
/** 用于控制是否生成 js、css 对应的 sourceMap (默认值:watch 模式下为 true,否则为 false) */
|
|
17
20
|
enableSourceMap?: boolean
|
|
18
21
|
|
|
@@ -40,24 +43,15 @@ export interface IMiniAppConfig {
|
|
|
40
43
|
*/
|
|
41
44
|
webpackChain?: (chain: Chain, webpack: typeof Webpack, PARSE_AST_TYPE: any) => void
|
|
42
45
|
|
|
43
|
-
/**
|
|
44
|
-
output
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* - 默认清空输出目录,可设置 clean: false 不清空
|
|
50
|
-
* - 可设置 clean: { keep: ['project.config.json'] } 保留指定文件
|
|
51
|
-
* - 注意 clean.keep 不支持函数
|
|
52
|
-
*/
|
|
53
|
-
clean?: boolean | {
|
|
54
|
-
/** 保留指定文件不删除 */
|
|
55
|
-
keep?: Array<string | RegExp> | string | RegExp
|
|
56
|
-
}
|
|
57
|
-
}
|
|
46
|
+
/** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/)
|
|
47
|
+
* vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/)
|
|
48
|
+
*/
|
|
49
|
+
output?: T extends 'vite'
|
|
50
|
+
? Pick<RollupOutputOptions, 'chunkFileNames'> & OutputExt
|
|
51
|
+
: Webpack.Configuration['output'] & OutputExt
|
|
58
52
|
|
|
59
53
|
/** 配置 postcss 相关插件 */
|
|
60
|
-
postcss?: IPostcssOption
|
|
54
|
+
postcss?: IPostcssOption<'mini'>
|
|
61
55
|
|
|
62
56
|
/** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
|
|
63
57
|
cssLoaderOption?: IOption
|
|
@@ -72,13 +66,13 @@ export interface IMiniAppConfig {
|
|
|
72
66
|
stylusLoaderOption?: IOption
|
|
73
67
|
|
|
74
68
|
/** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
75
|
-
mediaUrlLoaderOption?:
|
|
69
|
+
mediaUrlLoaderOption?: IUrlLoaderOption
|
|
76
70
|
|
|
77
71
|
/** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
78
|
-
fontUrlLoaderOption?:
|
|
72
|
+
fontUrlLoaderOption?: IUrlLoaderOption
|
|
79
73
|
|
|
80
74
|
/** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
|
|
81
|
-
imageUrlLoaderOption?:
|
|
75
|
+
imageUrlLoaderOption?: IUrlLoaderOption
|
|
82
76
|
|
|
83
77
|
/** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
|
|
84
78
|
miniCssExtractPluginOption?: IOption
|
|
@@ -97,16 +91,27 @@ export interface IMiniAppConfig {
|
|
|
97
91
|
|
|
98
92
|
/** 小程序编译过程的相关配置 */
|
|
99
93
|
compile?: {
|
|
100
|
-
exclude?:
|
|
101
|
-
include?:
|
|
94
|
+
exclude?: (string | RegExp)[]
|
|
95
|
+
include?: (string | RegExp)[]
|
|
96
|
+
filter?: (filename: string) => boolean
|
|
102
97
|
}
|
|
103
98
|
|
|
104
99
|
/** 插件内部使用 */
|
|
105
100
|
runtime?: Runtime
|
|
106
101
|
|
|
102
|
+
/** 使用的编译工具。可选值:webpack5、vite */
|
|
103
|
+
compiler?: Compiler<T>
|
|
104
|
+
|
|
107
105
|
/** 体验式功能 */
|
|
108
106
|
experimental?: {
|
|
109
107
|
/** 是否开启编译模式 */
|
|
110
|
-
compileMode?: boolean
|
|
108
|
+
compileMode?: boolean | string
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface IMiniFilesConfig {
|
|
113
|
+
[configName: string]: {
|
|
114
|
+
content: any
|
|
115
|
+
path: string
|
|
111
116
|
}
|
|
112
117
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CustomPluginOptions, ResolvedId, ResolveIdResult } from 'rollup'
|
|
2
|
+
|
|
3
|
+
interface IRollupPluginResolveIdOptions {
|
|
4
|
+
assertions?: Record<string, string>
|
|
5
|
+
custom?: CustomPluginOptions
|
|
6
|
+
isEntry?: boolean
|
|
7
|
+
skipSelf?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type TRollupResolveMethod = (
|
|
11
|
+
source: string,
|
|
12
|
+
importer?: string,
|
|
13
|
+
options?: IRollupPluginResolveIdOptions
|
|
14
|
+
) => Promise<ResolvedId | null>
|
|
15
|
+
|
|
16
|
+
export interface ILoaderMeta {
|
|
17
|
+
importFrameworkStatement: string
|
|
18
|
+
importFrameworkName: string
|
|
19
|
+
creator: string
|
|
20
|
+
creatorLocation: string
|
|
21
|
+
extraImportForWeb: string
|
|
22
|
+
execBeforeCreateWebApp: string
|
|
23
|
+
frameworkArgs: string
|
|
24
|
+
isNeedRawLoader?: boolean
|
|
25
|
+
mockAppStatement: string
|
|
26
|
+
modifyConfig?: (config: Record<string, any>, source: string) => void
|
|
27
|
+
modifyResolveId?: (res: {
|
|
28
|
+
source?: string
|
|
29
|
+
importer?: string
|
|
30
|
+
options?: IRollupPluginResolveIdOptions
|
|
31
|
+
name?: string
|
|
32
|
+
resolve: TRollupResolveMethod
|
|
33
|
+
}) => Promise<ResolveIdResult> | ResolveIdResult
|
|
34
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type Webpack from 'webpack'
|
|
2
2
|
import type Chain from 'webpack-chain'
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
3
|
+
import type { Input } from 'postcss'
|
|
4
|
+
import type { AppConfig } from '../../index'
|
|
5
|
+
import type { Compiler, CompilerTypes, CompilerWebpackTypes } from '../compiler'
|
|
5
6
|
import type { IModifyChainData } from '../hooks'
|
|
6
7
|
import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from './util'
|
|
7
8
|
import type { IH5Config } from './h5'
|
|
8
|
-
import type {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import type { IHarmonyConfig } from './harmony'
|
|
10
|
+
import type { IMiniAppConfig, IMiniFilesConfig } from './mini'
|
|
11
|
+
import type { IRNConfig } from './rn'
|
|
11
12
|
|
|
12
13
|
export type PluginItem<T = object> = string | [string, T] | [string, () => T | Promise<T>]
|
|
13
14
|
|
|
@@ -115,7 +116,7 @@ export interface IProjectBaseConfig {
|
|
|
115
116
|
jsMinimizer?: 'terser' | 'esbuild'
|
|
116
117
|
|
|
117
118
|
/** 配置 CSS 压缩工具 (默认 csso) */
|
|
118
|
-
cssMinimizer?: 'csso' | 'esbuild' | '
|
|
119
|
+
cssMinimizer?: 'csso' | 'esbuild' | 'lightningcss'
|
|
119
120
|
|
|
120
121
|
/** 配置 csso 工具以压缩 CSS 代码 */
|
|
121
122
|
csso?: TogglableOptions
|
|
@@ -139,11 +140,11 @@ export interface IProjectBaseConfig {
|
|
|
139
140
|
/** 模板循环次数 */
|
|
140
141
|
baseLevel?: number
|
|
141
142
|
|
|
142
|
-
/** 使用的开发框架。可选值:react、preact、
|
|
143
|
-
framework?: 'react' | 'preact' | '
|
|
143
|
+
/** 使用的开发框架。可选值:react、preact、vue3 */
|
|
144
|
+
framework?: 'react' | 'preact' | 'solid' | 'vue3'
|
|
144
145
|
frameworkExts?: string[]
|
|
145
146
|
|
|
146
|
-
/** 使用的编译工具。可选值:
|
|
147
|
+
/** 使用的编译工具。可选值:webpack5 */
|
|
147
148
|
compiler?: Compiler
|
|
148
149
|
|
|
149
150
|
/** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
|
|
@@ -185,18 +186,28 @@ export interface IProjectBaseConfig {
|
|
|
185
186
|
modifyWebpackChain?: (chain: Chain, webpack: typeof Webpack, data: IModifyChainData) => Promise<any>
|
|
186
187
|
|
|
187
188
|
/**
|
|
188
|
-
*
|
|
189
|
+
* 编译中修改 vite 配置
|
|
189
190
|
*/
|
|
190
|
-
|
|
191
|
+
modifyViteConfig?: (viteConfig: any, data: IModifyChainData) => void
|
|
191
192
|
|
|
192
193
|
/**
|
|
193
194
|
* 修改编译后的结果
|
|
194
195
|
*/
|
|
195
196
|
modifyBuildAssets?: (assets: any, miniPlugin?: any) => Promise<any>
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 修改编译过程中的页面组件配置
|
|
200
|
+
*/
|
|
201
|
+
modifyMiniConfigs?: (configMap: IMiniFilesConfig) => Promise<any>
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 修改 Taro 编译配置
|
|
205
|
+
*/
|
|
206
|
+
modifyRunnerOpts?: (opts: any) => Promise<any>
|
|
196
207
|
}
|
|
197
208
|
|
|
198
209
|
/** 暴露出来给 config/index 使用的配置类型,参考 https://github.com/NervJS/taro-doctor/blob/main/assets/config_schema.json */
|
|
199
|
-
export interface IProjectConfig {
|
|
210
|
+
export interface IProjectConfig<T extends CompilerTypes = CompilerWebpackTypes> {
|
|
200
211
|
/** 项目名称 */
|
|
201
212
|
projectName?: string
|
|
202
213
|
|
|
@@ -266,7 +277,7 @@ export interface IProjectConfig {
|
|
|
266
277
|
jsMinimizer?: 'terser' | 'esbuild'
|
|
267
278
|
|
|
268
279
|
/** 配置 CSS 压缩工具 (默认 csso) */
|
|
269
|
-
cssMinimizer?: 'csso' | 'esbuild' | '
|
|
280
|
+
cssMinimizer?: 'csso' | 'esbuild' | 'lightningcss'
|
|
270
281
|
|
|
271
282
|
/** 配置 csso 工具以压缩 CSS 代码 */
|
|
272
283
|
csso?: TogglableOptions
|
|
@@ -285,11 +296,8 @@ export interface IProjectConfig {
|
|
|
285
296
|
/** 一个 preset 是一系列 Taro 插件的集合,配置语法同 plugins */
|
|
286
297
|
presets?: PluginItem[]
|
|
287
298
|
|
|
288
|
-
/** 使用的开发框架。可选值:react、preact、
|
|
289
|
-
framework?: 'react' | 'preact' | '
|
|
290
|
-
|
|
291
|
-
/** 使用的编译工具。可选值:webpack4、webpack5 */
|
|
292
|
-
compiler?: Compiler
|
|
299
|
+
/** 使用的开发框架。可选值:react、preact、solid、vue3、 none */
|
|
300
|
+
framework?: 'react' | 'preact' | 'solid' | 'vue3' | 'none'
|
|
293
301
|
|
|
294
302
|
/** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
|
|
295
303
|
cache?: ICache
|
|
@@ -297,14 +305,34 @@ export interface IProjectConfig {
|
|
|
297
305
|
/** 控制 Taro 编译日志的输出方式 */
|
|
298
306
|
logger?: ILogger
|
|
299
307
|
|
|
300
|
-
/**
|
|
301
|
-
|
|
308
|
+
/** 使用的编译工具。可选值:webpack5、vite */
|
|
309
|
+
compiler?: Compiler<T>
|
|
302
310
|
|
|
303
311
|
/** 专属于 H5 的配置 */
|
|
304
|
-
h5?: IH5Config
|
|
312
|
+
h5?: IH5Config<T>
|
|
313
|
+
|
|
314
|
+
/** 专属于小程序的配置 */
|
|
315
|
+
mini?: IMiniAppConfig<T>
|
|
305
316
|
|
|
306
317
|
/** 专属于 RN 的配置 */
|
|
307
318
|
rn?: IRNConfig
|
|
308
319
|
|
|
320
|
+
harmony?: IHarmonyConfig<T>
|
|
321
|
+
|
|
309
322
|
[key: string]: any
|
|
310
323
|
}
|
|
324
|
+
|
|
325
|
+
export interface OutputExt {
|
|
326
|
+
/**
|
|
327
|
+
* 编译前清空输出目录
|
|
328
|
+
* @since Taro v3.6.9
|
|
329
|
+
* @description
|
|
330
|
+
* - 默认清空输出目录,可设置 clean: false 不清空
|
|
331
|
+
* - 可设置 clean: { keep: ['project.config.json'] } 保留指定文件
|
|
332
|
+
* - 注意 clean.keep 不支持函数
|
|
333
|
+
*/
|
|
334
|
+
clean?: boolean | {
|
|
335
|
+
/** 保留指定文件不删除 */
|
|
336
|
+
keep?: Array<string | RegExp> | string | RegExp
|
|
337
|
+
}
|
|
338
|
+
}
|
|
@@ -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,18 +75,29 @@ export interface IPxTransformOption {
|
|
|
72
75
|
designWidth?: number | ((size?: string | number | Input) => number)
|
|
73
76
|
/** 设计稿尺寸换算规则 */
|
|
74
77
|
deviceRatio?: TaroGeneral.TDeviceRatio
|
|
78
|
+
/** 平台 */
|
|
79
|
+
platform?: 'weapp' | 'h5' | string
|
|
80
|
+
/** 启用的能力 Scope 默认为 ['platform', 'size'] */
|
|
81
|
+
methods?: string[]
|
|
82
|
+
/** filter 回调函数,可 exclude 不处理的文件 */
|
|
83
|
+
exclude?: (fileName: string) => boolean
|
|
75
84
|
}
|
|
76
85
|
|
|
77
|
-
|
|
86
|
+
interface IBasePostcssOption {
|
|
78
87
|
autoprefixer?: TogglableOptions
|
|
79
88
|
pxtransform?: TogglableOptions<IPxTransformOption>
|
|
80
89
|
cssModules?: PostcssOption.cssModules
|
|
81
|
-
url?: PostcssOption.url
|
|
82
90
|
/** 插件 postcss-html-transform 相关配置, 一般启用了 @tarojs/plugin-html 插件才配置 */
|
|
83
91
|
htmltransform?: IHtmlTransformOption
|
|
84
92
|
[key: string]: any
|
|
85
93
|
}
|
|
86
94
|
|
|
95
|
+
export type IPostcssOption<T = 'h5' | 'harmony' | 'mini'> = T extends 'h5'
|
|
96
|
+
? IBasePostcssOption & { url?: PostcssOption.url }
|
|
97
|
+
: IBasePostcssOption
|
|
98
|
+
|
|
99
|
+
export type Config = ViteConfig | WebpackConfig
|
|
100
|
+
|
|
87
101
|
export interface ICopyOptions {
|
|
88
102
|
patterns: {
|
|
89
103
|
from: string
|