@tarojs/taro 3.6.9-alpha.2 → 3.6.9-alpha.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/taro",
3
- "version": "3.6.9-alpha.2",
3
+ "version": "3.6.9-alpha.4",
4
4
  "description": "Taro framework",
5
5
  "homepage": "https://github.com/nervjs/taro/tree/master/packages/taro#readme",
6
6
  "main": "index.js",
@@ -21,15 +21,11 @@
21
21
  "author": "O2Team",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@tarojs/api": "3.6.9-alpha.2",
25
- "@tarojs/runtime": "3.6.9-alpha.2"
24
+ "@tarojs/api": "3.6.9-alpha.4",
25
+ "@tarojs/runtime": "3.6.9-alpha.4"
26
26
  },
27
27
  "devDependencies": {
28
- "postcss": "^8.4.18",
29
- "@tarojs/helper": "3.6.9-alpha.2"
30
- },
31
- "peerDependencies": {
32
- "postcss": "^8.4.18"
28
+ "@tarojs/helper": "3.6.9-alpha.4"
33
29
  },
34
30
  "peerDependenciesMeta": {
35
31
  "@types/react": {
@@ -41,6 +37,9 @@
41
37
  "@types/webpack-dev-server": {
42
38
  "optional": true
43
39
  },
40
+ "postcss": {
41
+ "optional": true
42
+ },
44
43
  "vue": {
45
44
  "optional": true
46
45
  }
@@ -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,75 @@ 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
+ /** 压缩小程序 xml 文件的相关配置 */
19
23
  minifyXML?: {
24
+ /** 是否合并 xml 文件中的空格 (默认false) */
20
25
  collapseWhitespace?: boolean
21
26
  }
22
27
 
28
+ /**
29
+ * 自定义 Webpack 配置
30
+ * @param chain [webpackChain](https://github.com/neutrinojs/webpack-chain) 对象
31
+ * @param webpack webpack 实例
32
+ * @param PARSE_AST_TYPE 小程序编译时的文件类型集合
33
+ * @returns
34
+ */
23
35
  webpackChain?: (chain: Chain, webpack: typeof Webpack, PARSE_AST_TYPE: any) => void
36
+
37
+ /** 可用于修改、拓展 Webpack 的 [output](https://webpack.js.org/configuration/output/) 选项 */
24
38
  output?: Webpack.Configuration['output']
39
+
40
+ /** 配置 postcss 相关插件 */
25
41
  postcss?: IPostcssOption
42
+
43
+ /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
26
44
  cssLoaderOption?: IOption
45
+
46
+ /** [sass-loader](https://github.com/webpack-contrib/sass-loader) 的附加配置 */
27
47
  sassLoaderOption?: IOption
48
+
49
+ /** [less-loader](https://github.com/webpack-contrib/less-loader) 的附加配置 */
28
50
  lessLoaderOption?: IOption
51
+
52
+ /** [stylus-loader](https://github.com/shama/stylus-loader) 的附加配置 */
29
53
  stylusLoaderOption?: IOption
54
+
55
+ /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
30
56
  mediaUrlLoaderOption?: IOption
57
+
58
+ /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
31
59
  fontUrlLoaderOption?: IOption
60
+
61
+ /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
32
62
  imageUrlLoaderOption?: IOption
63
+
64
+ /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
33
65
  miniCssExtractPluginOption?: IOption
34
66
 
35
- customFilesTypes?: IMINI_APP_FILE_TYPE
67
+ /** 用于告诉 Taro 编译器需要抽取的公共文件 */
36
68
  commonChunks?: string[] | ((commonChunks: string[]) => string[])
37
- addChunkPages?: ((pages: Map<string, string[]>, pagesNames?: string[]) => void)
69
+
70
+ /** 为某些页面单独指定需要引用的公共文件 */
71
+ addChunkPages?: (pages: Map<string, string[]>, pagesNames?: string[]) => void
72
+
73
+ /** 优化主包的体积大小 */
38
74
  optimizeMainPackage?: {
39
75
  enable?: boolean
40
76
  exclude?: any[]
41
77
  }
42
78
 
79
+ /** 小程序编译过程的相关配置 */
43
80
  compile?: {
44
81
  exclude?: any[]
45
82
  include?: any[]
46
83
  }
84
+
85
+ /** 插件内部使用 */
47
86
  runtime?: Runtime
48
87
  }
@@ -6,17 +6,37 @@ import type { IModifyWebpackChain } from '../hooks'
6
6
  import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from './util'
7
7
  import type { IH5Config } from './h5'
8
8
  import type { IMiniAppConfig } from './mini'
9
+ import { IRNConfig } from './rn'
9
10
 
10
- export type PluginItem = string | [string, object]
11
+ export type PluginItem = string | [string, object] | [string, () => object | Promise<object>]
11
12
 
12
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
+ */
13
21
  enable?: boolean
22
+
23
+ /**
24
+ * 当依赖的文件或该文件的依赖改变时,使缓存失效。
25
+ * @description 详详情请参考 [WebpackConfig.cache.buildDependencies](https://webpack.js.org/configuration/cache/#cachebuilddependencies)。
26
+ */
14
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
+ */
15
33
  name?: string
16
34
  }
17
35
 
18
36
  interface ILogger {
37
+ /** 是否简化输出日志 (默认值 true)*/
19
38
  quiet: boolean
39
+ /** 是否输出 Webpack Stats 信息 (默认值 false) */
20
40
  stats: boolean
21
41
  }
22
42
 
@@ -137,7 +157,73 @@ export interface IProjectBaseConfig {
137
157
  modifyBuildAssets?: (assets: any, miniPlugin?: any) => Promise<any>
138
158
  }
139
159
 
140
- export interface IProjectConfig extends IProjectBaseConfig {
160
+ /** 暴露出来给 config/index 使用的配置类型,参考 https://github.com/NervJS/taro-doctor/blob/main/assets/config_schema.json */
161
+ export interface IProjectConfig {
162
+ /** 项目名称 */
163
+ projectName?: string
164
+
165
+ /** 项目创建日期 */
166
+ date?: string
167
+
168
+ /** 设计稿尺寸 */
169
+ designWidth?: number | ((size?: string | number | Input) => number)
170
+
171
+ /** 设计稿尺寸换算规则 */
172
+ deviceRatio?: TaroGeneral.TDeviceRatio
173
+
174
+ /** 源码存放目录 (默认值:'src') */
175
+ sourceRoot?: string
176
+
177
+ /** 代码编译后的生产目录 (默认值:'dist') */
178
+ outputRoot?: string
179
+
180
+ /** 用于设置环境变量 (除了NODE_ENV以外,其他环境变量建议在根目录下的.env文件中) */
181
+ env?: IOption
182
+
183
+ /** 用于配置目录别名,从而方便书写代码引用路径 */
184
+ alias?: IOption
185
+
186
+ /** 用于配置一些全局变量供代码中进行使用(建议放在根目录下的.env文件中) */
187
+ defineConstants?: IOption
188
+
189
+ /** 用于把文件从源码目录直接拷贝到编译后的生产目录 */
190
+ copy?: ICopyOptions
191
+
192
+ /** 配置 JS 压缩工具 (默认 terser) */
193
+ jsMinimizer?: 'terser' | 'esbuild'
194
+
195
+ /** 配置 CSS 压缩工具 (默认 csso) */
196
+ cssMinimizer?: 'csso' | 'esbuild' | 'parcelCss'
197
+
198
+ /** 配置 csso 工具以压缩 CSS 代码 */
199
+ csso?: TogglableOptions
200
+
201
+ /** 配置 terser 工具以压缩 JS 代码 */
202
+ terser?: TogglableOptions
203
+
204
+ esbuild?: Record<'minify', TogglableOptions>
205
+
206
+ /** 用于控制对 scss 代码的编译行为,默认使用 dart-sass,具体配置可以参考 https://www.npmjs.com/package/sass */
207
+ sass?: ISassOptions
208
+
209
+ /** 配置 Taro 插件 */
210
+ plugins?: PluginItem[]
211
+
212
+ /** 一个 preset 是一系列 Taro 插件的集合,配置语法同 plugins */
213
+ presets?: PluginItem[]
214
+
215
+ /** 使用的开发框架。可选值:react、preact、nerv、vue、vue3 */
216
+ framework?: 'react' | 'preact' | 'nerv' | 'vue' | 'vue3'
217
+
218
+ /** 使用的编译工具。可选值:webpack4、webpack5 */
219
+ compiler?: Compiler
220
+
221
+ /** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
222
+ cache?: ICache
223
+
224
+ /** 控制 Taro 编译日志的输出方式 */
225
+ logger?: ILogger
226
+
141
227
  /** 专属于小程序的配置 */
142
228
  mini?: IMiniAppConfig
143
229
 
@@ -145,7 +231,7 @@ export interface IProjectConfig extends IProjectBaseConfig {
145
231
  h5?: IH5Config
146
232
 
147
233
  /** 专属于 RN 的配置 */
148
- rn?: IH5Config
234
+ rn?: IRNConfig
149
235
 
150
236
  [key: string]: any
151
237
  }
@@ -0,0 +1,52 @@
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
+ }
41
+
42
+ resolve?: any
43
+
44
+ /** 支持多 className 转换,以 classname 或 style 结尾的, 提取前缀, 然后根据前缀,再生成对应的 xxxStyle。如:barClassName -> barStyle。默认值 false,不开启 */
45
+ enableMultipleClassName?: boolean
46
+
47
+ /** 当标签 style 属性值是数组时转换成对象。默认值 false,不开启 */
48
+ enableMergeStyle?: boolean
49
+
50
+ /** 将 svg 文件转换为组件引入。默认值 false,不开启 */
51
+ enableSvgTransform?: boolean
52
+ }
@@ -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