@tarojs/taro 3.6.8 → 3.6.9-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.
@@ -1,91 +1,307 @@
1
1
  import type Webpack from 'webpack'
2
2
  import type Chain from 'webpack-chain'
3
+ import { type Input } from 'postcss'
3
4
  import type { Compiler } from '../compiler'
4
5
  import type { IModifyWebpackChain } from '../hooks'
5
- import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from "./util"
6
+ import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from './util'
6
7
  import type { IH5Config } from './h5'
7
8
  import type { IMiniAppConfig } from './mini'
9
+ import { IRNConfig } from './rn'
8
10
 
9
- export type PluginItem = string | [string, object]
11
+ export type PluginItem = string | [string, object] | [string, () => object | Promise<object>]
10
12
 
11
13
  interface ICache {
14
+ /**
15
+ * 是否开启持久化缓存 (默认值 false)
16
+ * @description ```
17
+ * 值为 false 时:开发模式下 WebpackConfig.cache.type = 'memory',而生产模式下 WebpackConfig.cache = false;
18
+ * 值为 true 时:开发模式和生产模式下均为 WebpackConfig.cache.type = 'filesystem'
19
+ * ```
20
+ */
12
21
  enable?: boolean
22
+
23
+ /**
24
+ * 当依赖的文件或该文件的依赖改变时,使缓存失效。
25
+ * @description 详详情请参考 [WebpackConfig.cache.buildDependencies](https://webpack.js.org/configuration/cache/#cachebuilddependencies)。
26
+ */
13
27
  buildDependencies?: Record<string, any>
28
+
29
+ /**
30
+ * 缓存子目录的名称 (默认值 process.env.NODE_ENV-process.env.TARO_ENV)
31
+ * @description 详情请参考 [WebpackConfig.cache.name](https://webpack.js.org/configuration/cache/#cachename)
32
+ */
14
33
  name?: string
15
34
  }
16
35
 
17
36
  interface ILogger {
37
+ /** 是否简化输出日志 (默认值 true)*/
18
38
  quiet: boolean
39
+ /** 是否输出 Webpack Stats 信息 (默认值 false) */
19
40
  stats: boolean
20
41
  }
21
42
 
22
43
  export interface IProjectBaseConfig {
23
44
  isWatch?: boolean
24
45
  port?: number
46
+ /** 项目名称 */
25
47
  projectName?: string
48
+
49
+ /** 项目创建日期 */
26
50
  date?: string
27
- designWidth?: number | ((size?: string | number) => number)
51
+
52
+ /** 设计稿尺寸 */
53
+ designWidth?: number | ((size?: string | number | Input) => number)
54
+
55
+ /** 设计稿尺寸换算规则 */
28
56
  deviceRatio?: TaroGeneral.TDeviceRatio
57
+
29
58
  watcher?: any[]
59
+
60
+ /** 源码存放目录 (默认值:'src') */
30
61
  sourceRoot?: string
62
+
63
+ /** 代码编译后的生产目录 (默认值:'dist') */
31
64
  outputRoot?: string
65
+
66
+ /**
67
+ * 用于配置`process.env.xxxx`相关的环境变量
68
+ * @deprecated 建议使用根目录下的 .env 文件替代
69
+ * @description 注意:这里的环境变量只能在业务代码中使用,编译时的 node 环境中无法使用
70
+ * @example
71
+ * ```ts
72
+ * // config/index.ts
73
+ * export default defineConfig({
74
+ * env: {
75
+ * xxxx: '"测试"'
76
+ * }
77
+ * })
78
+ *
79
+ * // src/app.ts
80
+ * onShow() {
81
+ * console.log(process.env.xxxx) // 打印 "测试"
82
+ * }
83
+ * ```
84
+ */
32
85
  env?: IOption
86
+
87
+ /** 用于配置目录别名,从而方便书写代码引用路径 */
33
88
  alias?: IOption
89
+
90
+ /**
91
+ * 用于配置一些常量供代码中进行全局替换使用
92
+ * @description 注意:这里的环境变量只能在业务代码中使用,编译时的 node 环境中无法使用
93
+ * @example
94
+ * ```ts
95
+ * // config/index.ts
96
+ * export default defineConfig({
97
+ * defineConstants: {
98
+ * __TEST__: JSON.stringify('test')
99
+ * }
100
+ * })
101
+ *
102
+ * // src/app.ts
103
+ * onShow() {
104
+ * console.log(__TEST__) // 打印 "test"
105
+ * }
106
+ * ```
107
+ */
34
108
  defineConstants?: IOption
109
+
110
+ /** 用于把文件从源码目录直接拷贝到编译后的生产目录 */
35
111
  copy?: ICopyOptions
112
+
113
+ /** 配置 JS 压缩工具 (默认 terser) */
36
114
  jsMinimizer?: 'terser' | 'esbuild'
115
+
116
+ /** 配置 CSS 压缩工具 (默认 csso) */
37
117
  cssMinimizer?: 'csso' | 'esbuild' | 'parcelCss'
118
+
119
+ /** 配置 csso 工具以压缩 CSS 代码 */
38
120
  csso?: TogglableOptions
121
+
122
+ /** 配置 terser 工具以压缩 JS 代码 */
39
123
  terser?: TogglableOptions
124
+
40
125
  esbuild?: Record<'minify', TogglableOptions>
126
+
41
127
  uglify?: TogglableOptions
128
+
129
+ /** 用于控制对 scss 代码的编译行为,默认使用 dart-sass,具体配置可以参考 https://www.npmjs.com/package/sass */
42
130
  sass?: ISassOptions
131
+
132
+ /** 配置 Taro 插件 */
43
133
  plugins?: PluginItem[]
134
+
135
+ /** 一个 preset 是一系列 Taro 插件的集合,配置语法同 plugins */
44
136
  presets?: PluginItem[]
137
+
138
+ /** 模板循环次数 */
45
139
  baseLevel?: number
46
- framework?: string
140
+
141
+ /** 使用的开发框架。可选值:react、preact、nerv、vue、vue3 */
142
+ framework?: 'react' | 'preact' | 'nerv' | 'vue' | 'vue3'
47
143
  frameworkExts?: string[]
144
+
145
+ /** 使用的编译工具。可选值:webpack4、webpack5 */
48
146
  compiler?: Compiler
147
+
148
+ /** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
49
149
  cache?: ICache
150
+
151
+ /** 控制 Taro 编译日志的输出方式 */
50
152
  logger?: ILogger
153
+
154
+ /** 用于控制是否生成 js、css 对应的 sourceMap */
51
155
  enableSourceMap?: boolean
156
+
52
157
  /**
53
158
  * 编译开始
54
159
  */
55
160
  onBuildStart?: (...args: any[]) => Promise<any>
161
+
56
162
  /**
57
163
  * 编译完成(启动项目后首次编译结束后会触发一次)
58
164
  */
59
165
  onBuildComplete?: (...args: any[]) => Promise<any>
166
+
60
167
  /**
61
168
  * 编译结束(保存代码每次编译结束后都会触发)
62
169
  */
63
- onBuildFinish?: (res: { error, stats, isWatch }) => Promise<any>
170
+ onBuildFinish?: (res: { error; stats; isWatch }) => Promise<any>
171
+
64
172
  /**
65
173
  * 修改编译过程中的页面组件配置
66
174
  */
67
175
  onCompilerMake?: (compilation: Webpack.Compilation, compiler: Webpack.Compiler, plugin: any) => Promise<any>
176
+
68
177
  onWebpackChainReady?: (webpackChain: Chain) => Promise<any>
178
+
69
179
  /**
70
180
  * 编译中修改 webpack 配置,在这个钩子中,你可以对 webpackChain 作出想要的调整,等同于配置 [`webpackChain`](./config-detail#miniwebpackchain)
71
181
  */
72
182
  modifyWebpackChain?: (chain: Chain, webpack: typeof Webpack, data: IModifyWebpackChain) => Promise<any>
183
+
73
184
  /**
74
185
  * 修改编译过程中的页面组件配置
75
186
  */
76
187
  modifyMiniConfigs?: (configMap: any) => Promise<any>
188
+
77
189
  /**
78
190
  * 修改编译后的结果
79
191
  */
80
192
  modifyBuildAssets?: (assets: any, miniPlugin?: any) => Promise<any>
81
193
  }
82
194
 
83
- export interface IProjectConfig extends IProjectBaseConfig {
84
- ui?: {
85
- extraWatchFiles?: any[]
86
- }
195
+ /** 暴露出来给 config/index 使用的配置类型,参考 https://github.com/NervJS/taro-doctor/blob/main/assets/config_schema.json */
196
+ export interface IProjectConfig {
197
+ /** 项目名称 */
198
+ projectName?: string
199
+
200
+ /** 项目创建日期 */
201
+ date?: string
202
+
203
+ /** 设计稿尺寸 */
204
+ designWidth?: number | ((size?: string | number | Input) => number)
205
+
206
+ /** 设计稿尺寸换算规则 */
207
+ deviceRatio?: TaroGeneral.TDeviceRatio
208
+
209
+ /** 源码存放目录 (默认值:'src') */
210
+ sourceRoot?: string
211
+
212
+ /** 代码编译后的生产目录 (默认值:'dist') */
213
+ outputRoot?: string
214
+
215
+ /**
216
+ * 用于配置`process.env.xxxx`相关的环境变量
217
+ * @deprecated 建议使用根目录下的 .env 文件替代
218
+ * @description 注意:这里的环境变量只能在业务代码中使用,编译时的 node 环境中无法使用
219
+ * @example
220
+ * ```ts
221
+ * // config/index.ts
222
+ * export default defineConfig({
223
+ * env: {
224
+ * xxxx: '"测试"'
225
+ * }
226
+ * })
227
+ *
228
+ * // src/app.ts
229
+ * onShow() {
230
+ * console.log(process.env.xxxx) // 打印 "测试"
231
+ * }
232
+ * ```
233
+ */
234
+ env?: IOption
235
+
236
+ /** 用于配置目录别名,从而方便书写代码引用路径 */
237
+ alias?: IOption
238
+
239
+ /**
240
+ * 用于配置一些常量供代码中进行全局替换使用
241
+ * @description 注意:这里的环境变量只能在业务代码中使用,编译时的 node 环境中无法使用
242
+ * @example
243
+ * ```ts
244
+ * // config/index.ts
245
+ * export default defineConfig({
246
+ * defineConstants: {
247
+ * __TEST__: JSON.stringify('test')
248
+ * }
249
+ * })
250
+ *
251
+ * // src/app.ts
252
+ * onShow() {
253
+ * console.log(__TEST__) // 打印 "test"
254
+ * }
255
+ * ```
256
+ */
257
+ defineConstants?: IOption
258
+
259
+ /** 用于把文件从源码目录直接拷贝到编译后的生产目录 */
260
+ copy?: ICopyOptions
261
+
262
+ /** 配置 JS 压缩工具 (默认 terser) */
263
+ jsMinimizer?: 'terser' | 'esbuild'
264
+
265
+ /** 配置 CSS 压缩工具 (默认 csso) */
266
+ cssMinimizer?: 'csso' | 'esbuild' | 'parcelCss'
267
+
268
+ /** 配置 csso 工具以压缩 CSS 代码 */
269
+ csso?: TogglableOptions
270
+
271
+ /** 配置 terser 工具以压缩 JS 代码 */
272
+ terser?: TogglableOptions
273
+
274
+ esbuild?: Record<'minify', TogglableOptions>
275
+
276
+ /** 用于控制对 scss 代码的编译行为,默认使用 dart-sass,具体配置可以参考 https://www.npmjs.com/package/sass */
277
+ sass?: ISassOptions
278
+
279
+ /** 配置 Taro 插件 */
280
+ plugins?: PluginItem[]
281
+
282
+ /** 一个 preset 是一系列 Taro 插件的集合,配置语法同 plugins */
283
+ presets?: PluginItem[]
284
+
285
+ /** 使用的开发框架。可选值:react、preact、nerv、vue、vue3 */
286
+ framework?: 'react' | 'preact' | 'nerv' | 'vue' | 'vue3'
287
+
288
+ /** 使用的编译工具。可选值:webpack4、webpack5 */
289
+ compiler?: Compiler
290
+
291
+ /** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
292
+ cache?: ICache
293
+
294
+ /** 控制 Taro 编译日志的输出方式 */
295
+ logger?: ILogger
296
+
297
+ /** 专属于小程序的配置 */
87
298
  mini?: IMiniAppConfig
299
+
300
+ /** 专属于 H5 的配置 */
88
301
  h5?: IH5Config
89
- rn?: IH5Config
302
+
303
+ /** 专属于 RN 的配置 */
304
+ rn?: IRNConfig
305
+
90
306
  [key: string]: any
91
307
  }
@@ -0,0 +1,56 @@
1
+ import type Webpack from 'webpack'
2
+ import type Chain from 'webpack-chain'
3
+ import type webpackDevServer from 'webpack-dev-server'
4
+ import type HtmlWebpackPlugin from 'html-webpack-plugin'
5
+ import type { IOption, IPostcssOption } from './util'
6
+
7
+ export interface IRNConfig {
8
+ /** 设置 RN bundle 中注册应用的名称 */
9
+ appName: string
10
+
11
+ /** entry 利用模块查找规则{name}.{platform}.{ext}自动区分平台 */
12
+ entry?: string
13
+
14
+ /** 设置 Metro 打包生成 bundle 的输出路径,默认 dist 目录下 */
15
+ output?: any
16
+
17
+ /** [sass](https://github.com/sass/node-sass#options) 相关配置 */
18
+ sass?: IOption
19
+
20
+ /** [less](https://lesscss.org/usage/#less-options) 相关配置 */
21
+ less?: IOption
22
+
23
+ /** [stylus](https://github.com/NervJS/taro/blob/next/packages/taro-rn-style-transformer/README.md#rnstylus) 相关配置 */
24
+ stylus?: IOption
25
+
26
+ /** 配置 postcss 相关插件 */
27
+ postcss?: {
28
+ /** postcss 配置,参考 https://github.com/postcss/postcss#options */
29
+ options?: any
30
+ /** 默认true,控制是否对 css value 进行 scalePx2dp 转换,pxtransform配置 enable 才生效 */
31
+ scalable?: boolean
32
+ pxtransform?: {
33
+ enable?: boolean
34
+ /** 插件 pxtransform 配置项 */
35
+ config?: {
36
+ additionalProperties?: boolean
37
+ [key: string]: any
38
+ }
39
+ },
40
+ cssModules?: {
41
+ enable: boolean
42
+ },
43
+ [key: string]: any
44
+ }
45
+
46
+ resolve?: any
47
+
48
+ /** 支持多 className 转换,以 classname 或 style 结尾的, 提取前缀, 然后根据前缀,再生成对应的 xxxStyle。如:barClassName -> barStyle。默认值 false,不开启 */
49
+ enableMultipleClassName?: boolean
50
+
51
+ /** 当标签 style 属性值是数组时转换成对象。默认值 false,不开启 */
52
+ enableMergeStyle?: boolean
53
+
54
+ /** 将 svg 文件转换为组件引入。默认值 false,不开启 */
55
+ enableSvgTransform?: boolean
56
+ }
@@ -1,3 +1,5 @@
1
+ import { type Input } from 'postcss'
2
+
1
3
  export type Func = (...args: any[]) => any
2
4
 
3
5
  export type IOption = Record<string, any>
@@ -9,7 +11,9 @@ export type TogglableOptions<T = IOption> = {
9
11
 
10
12
  export namespace PostcssOption {
11
13
  export type cssModules = TogglableOptions<{
14
+ /** 转换模式,取值为 global/module */
12
15
  namingPattern: 'global' | string
16
+ /** 自定义生成的class名称规则 */
13
17
  generateScopedName: string | ((localName: string, absoluteFilePath: string) => string)
14
18
  }>
15
19
  export type url = TogglableOptions<{
@@ -18,11 +22,65 @@ export namespace PostcssOption {
18
22
  }>
19
23
  }
20
24
 
25
+ export interface IHtmlTransformOption {
26
+ /** 是否启用 postcss-html-transform 插件 */
27
+ enable?: boolean
28
+ config?: {
29
+ /** 当前编译平台 (此选项插件内部根据编译平台自行生成,无需传入) */
30
+ readonly platform?: string
31
+ /** 设置是否去除 cursor 相关样式 (h5默认值:true) */
32
+ removeCursorStyle: boolean
33
+ }
34
+ }
35
+
36
+ export interface IPxTransformOption {
37
+ /** 设置 1px 是否需要被转换 */
38
+ onePxTransform?: boolean
39
+ /** REM 单位允许的小数位 */
40
+ unitPrecision?: number
41
+ /** 允许转换的属性列表 (默认 [*]) */
42
+ propList?: string[]
43
+ /** 黑名单里的选择器将会被忽略 */
44
+ selectorBlackList?: Array<string | RegExp>
45
+ /** 直接替换而不是追加一条进行覆盖 */
46
+ replace?: boolean
47
+ /** 允许媒体查询里的 px 单位转换 */
48
+ mediaQuery?: boolean
49
+ /** 设置一个可被转换的最小 px 值 */
50
+ minPixelValue?: number
51
+ /**
52
+ * 转换后的单位,可选值为 rpx、vw、rem,当前仅支持小程序 (默认 rpx) 和 Web 端 (默认 rem)
53
+ * @description Web 端使用 rem 单位时会注入脚本用于设置 body 上的 font-size 属性,其他单位无该操作
54
+ */
55
+ targetUnit?: 'rpx' | 'vw' | 'rem'
56
+ /**
57
+ * H5 字体尺寸大小基准值,开发者可以自行调整单位换算的基准值(默认20)
58
+ * @supported h5
59
+ */
60
+ baseFontSize?: number
61
+ /**
62
+ * H5 根节点 font-size 的最大值 (默认 40)
63
+ * @supported h5
64
+ */
65
+ maxRootSize?: number
66
+ /**
67
+ * H5 根节点 font-size 的最小值(默认 20)
68
+ * @supported h5
69
+ */
70
+ minRootSize?: number
71
+ /** 设计稿尺寸 */
72
+ designWidth?: number | ((size?: string | number | Input) => number)
73
+ /** 设计稿尺寸换算规则 */
74
+ deviceRatio?: TaroGeneral.TDeviceRatio
75
+ }
76
+
21
77
  export interface IPostcssOption {
22
78
  autoprefixer?: TogglableOptions
23
- pxtransform?: TogglableOptions
79
+ pxtransform?: TogglableOptions<IPxTransformOption>
24
80
  cssModules?: PostcssOption.cssModules
25
81
  url?: PostcssOption.url
82
+ /** 插件 postcss-html-transform 相关配置, 一般启用了 @tarojs/plugin-html 插件才配置 */
83
+ htmltransform?: IHtmlTransformOption
26
84
  [key: string]: any
27
85
  }
28
86
 
@@ -96,9 +154,9 @@ export const enum CONFIG_TYPES {
96
154
  }
97
155
 
98
156
  export type IMINI_APP_FILE_TYPE = {
99
- TEMPL: TEMPLATE_TYPES,
100
- STYLE: STYLE_TYPES,
101
- SCRIPT: SCRIPT_TYPES,
157
+ TEMPL: TEMPLATE_TYPES
158
+ STYLE: STYLE_TYPES
159
+ SCRIPT: SCRIPT_TYPES
102
160
  CONFIG: CONFIG_TYPES
103
161
  }
104
162
 
package/types/index.d.ts CHANGED
@@ -130,6 +130,8 @@
130
130
  /// <reference types="@tarojs/plugin-platform-swan/types/shims-swan" />
131
131
  /// <reference types="@tarojs/plugin-platform-tt/types/shims-tt" />
132
132
  /// <reference types="@tarojs/plugin-platform-weapp/types/shims-weapp" />
133
+ /// <reference types="@tarojs/taro-h5/types/overlay" />
134
+ /// <reference types="@tarojs/taro-rn/types/overlay" />
133
135
 
134
136
  export = Taro
135
137
  export as namespace Taro
@@ -41,6 +41,7 @@
41
41
  /// <reference path="api/payment/index.d.ts" />
42
42
  /// <reference path="api/storage/index.d.ts" />
43
43
  /// <reference path="api/storage/background-fetch.d.ts" />
44
+ /// <reference path="api/storage/cache-manager.d.ts" />
44
45
  /// <reference path="api/data-analysis/index.d.ts" />
45
46
  /// <reference path="api/canvas/index.d.ts" />
46
47
  /// <reference path="api/media/map.d.ts" />
@@ -73,6 +74,7 @@
73
74
  /// <reference path="api/open-api/favorites.d.ts" />
74
75
  /// <reference path="api/open-api/license-plate.d.ts" />
75
76
  /// <reference path="api/open-api/channels.d.ts" />
77
+ /// <reference path="api/open-api/device-voip.d.ts" />
76
78
  /// <reference path="api/open-api/group.d.ts" />
77
79
  /// <reference path="api/open-api/customer-service.d.ts" />
78
80
  /// <reference path="api/device/bluetooth.d.ts" />
@@ -88,6 +90,7 @@
88
90
  /// <reference path="api/device/clipboard.d.ts" />
89
91
  /// <reference path="api/device/network.d.ts" />
90
92
  /// <reference path="api/device/screen.d.ts" />
93
+ /// <reference path="api/device/sms.d.ts" />
91
94
  /// <reference path="api/device/keyboard.d.ts" />
92
95
  /// <reference path="api/device/phone.d.ts" />
93
96
  /// <reference path="api/device/accelerometer.d.ts" />
@@ -99,6 +102,7 @@
99
102
  /// <reference path="api/device/vibrate.d.ts" />
100
103
  /// <reference path="api/ai/visionkit.d.ts" />
101
104
  /// <reference path="api/ai/face.d.ts" />
105
+ /// <reference path="api/ai/inference.d.ts" />
102
106
  /// <reference path="api/worker/index.d.ts" />
103
107
  /// <reference path="api/wxml/index.d.ts" />
104
108
  /// <reference path="api/ext/index.d.ts" />