@tarojs/taro 3.7.0-alpha.16 → 3.7.0-alpha.19

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.7.0-alpha.16",
3
+ "version": "3.7.0-alpha.19",
4
4
  "description": "Taro framework",
5
5
  "homepage": "https://github.com/nervjs/taro/tree/master/packages/taro#readme",
6
6
  "main": "index.js",
@@ -21,11 +21,12 @@
21
21
  "author": "O2Team",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@tarojs/api": "3.7.0-alpha.16",
25
- "@tarojs/runtime": "3.7.0-alpha.16"
24
+ "@tarojs/api": "3.7.0-alpha.19",
25
+ "@tarojs/runtime": "3.7.0-alpha.19"
26
26
  },
27
27
  "devDependencies": {
28
- "@tarojs/helper": "3.7.0-alpha.16"
28
+ "@tarojs/helper": "3.7.0-alpha.19",
29
+ "@tarojs/shared": "3.7.0-alpha.19"
29
30
  },
30
31
  "peerDependenciesMeta": {
31
32
  "@types/react": {
@@ -37,6 +38,9 @@
37
38
  "@types/webpack-dev-server": {
38
39
  "optional": true
39
40
  },
41
+ "@types/postcss-url": {
42
+ "optional": true
43
+ },
40
44
  "postcss": {
41
45
  "optional": true
42
46
  },
@@ -1,7 +1,9 @@
1
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,8 +2,9 @@ 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
6
  import type { OutputOptions as RollupOutputOptions } from 'rollup'
7
+ import type { CompilerTypes, CompilerWebpackTypes } from '../compiler'
7
8
 
8
9
  export interface IH5RouterConfig {
9
10
  /** 配置路由模式 */
@@ -17,7 +18,7 @@ export interface IH5RouterConfig {
17
18
  forcePath?: string
18
19
  }
19
20
 
20
- export interface IH5Config {
21
+ export interface IH5Config <T extends CompilerTypes = CompilerWebpackTypes> {
21
22
  /** 设置输出解析文件的目录(默认值:'/')*/
22
23
  publicPath?: string
23
24
 
@@ -36,11 +37,10 @@ export interface IH5Config {
36
37
  */
37
38
  webpackChain?: (chain: Chain, webpack: typeof Webpack) => void
38
39
 
39
- /** 可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/) */
40
- output?: Webpack.Configuration['output']
41
-
42
- /** vite 编译模式下,用于修改、扩展 rollup output,配置想参考[官方文档](https://rollupjs.org/configuration-options/) */
43
- viteOutput?: RollupOutputOptions
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
44
 
45
45
  /** 路由相关的配置 */
46
46
  router?: IH5RouterConfig
@@ -83,13 +83,13 @@ export interface IH5Config {
83
83
  stylusLoaderOption?: IOption
84
84
 
85
85
  /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
86
- mediaUrlLoaderOption?: IOption
86
+ mediaUrlLoaderOption?: IUrlLoaderOption
87
87
 
88
88
  /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
89
- fontUrlLoaderOption?: IOption
89
+ fontUrlLoaderOption?: IUrlLoaderOption
90
90
 
91
91
  /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
92
- imageUrlLoaderOption?: IOption
92
+ imageUrlLoaderOption?: IUrlLoaderOption
93
93
 
94
94
  /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
95
95
  miniCssExtractPluginOption?: IOption
@@ -104,7 +104,7 @@ export interface IH5Config {
104
104
  useDeprecatedAdapterComponent?: boolean
105
105
 
106
106
  /** 配置 postcss 相关插件 */
107
- postcss?: IPostcssOption
107
+ postcss?: IPostcssOption<'H5'>
108
108
 
109
109
  /** html-webpack-plugin 的具体配置 */
110
110
  htmlPluginOption?: HtmlWebpackPlugin.Options
@@ -1,6 +1,8 @@
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 { CompilerTypes, CompilerWebpackTypes } from '../compiler'
4
6
 
5
7
  interface Runtime {
6
8
  enableInnerHTML: boolean
@@ -12,7 +14,22 @@ interface Runtime {
12
14
  enableMutationObserver: boolean
13
15
  }
14
16
 
15
- export interface IMiniAppConfig {
17
+ interface OutputExt {
18
+ /**
19
+ * 编译前清空输出目录
20
+ * @since Taro v3.6.9
21
+ * @description
22
+ * - 默认清空输出目录,可设置 clean: false 不清空
23
+ * - 可设置 clean: { keep: ['project.config.json'] } 保留指定文件
24
+ * - 注意 clean.keep 不支持函数
25
+ */
26
+ clean?: boolean | {
27
+ /** 保留指定文件不删除 */
28
+ keep?: Array<string | RegExp> | string | RegExp
29
+ }
30
+ }
31
+
32
+ export interface IMiniAppConfig<T extends CompilerTypes = CompilerWebpackTypes> {
16
33
  /** 默认值:'cheap-module-source-map', 具体参考[Webpack devtool 配置](https://webpack.js.org/configuration/devtool/#devtool) */
17
34
  sourceMapType?: string
18
35
 
@@ -37,24 +54,15 @@ export interface IMiniAppConfig {
37
54
  */
38
55
  webpackChain?: (chain: Chain, webpack: typeof Webpack, PARSE_AST_TYPE: any) => void
39
56
 
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
- }
57
+ /** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/)
58
+ * vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/)
59
+ */
60
+ output?: T extends 'vite'
61
+ ? Pick<RollupOutputOptions, 'chunkFileNames'> & OutputExt
62
+ : Webpack.Configuration['output'] & OutputExt
55
63
 
56
64
  /** 配置 postcss 相关插件 */
57
- postcss?: IPostcssOption
65
+ postcss?: IPostcssOption<'mini'>
58
66
 
59
67
  /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
60
68
  cssLoaderOption?: IOption
@@ -69,13 +77,13 @@ export interface IMiniAppConfig {
69
77
  stylusLoaderOption?: IOption
70
78
 
71
79
  /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
72
- mediaUrlLoaderOption?: IOption
80
+ mediaUrlLoaderOption?: IUrlLoaderOption
73
81
 
74
82
  /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
75
- fontUrlLoaderOption?: IOption
83
+ fontUrlLoaderOption?: IUrlLoaderOption
76
84
 
77
85
  /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
78
- imageUrlLoaderOption?: IOption
86
+ imageUrlLoaderOption?: IUrlLoaderOption
79
87
 
80
88
  /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
81
89
  miniCssExtractPluginOption?: IOption
@@ -104,7 +112,7 @@ export interface IMiniAppConfig {
104
112
 
105
113
  export interface IMiniFilesConfig {
106
114
  [configName: string]: {
107
- content: Config
115
+ content: any
108
116
  path: string
109
117
  }
110
118
  }
@@ -1,7 +1,7 @@
1
1
  import type Webpack from 'webpack'
2
2
  import type Chain from 'webpack-chain'
3
3
  import { type Input } from 'postcss'
4
- import type { Compiler } from '../compiler'
4
+ import type { Compiler, IPrebundle, CompilerTypes, CompilerWebpackTypes } from '../compiler'
5
5
  import type { IModifyChainData } from '../hooks'
6
6
  import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from './util'
7
7
  import type { IH5Config } from './h5'
@@ -203,7 +203,7 @@ export interface IProjectBaseConfig {
203
203
  }
204
204
 
205
205
  /** 暴露出来给 config/index 使用的配置类型,参考 https://github.com/NervJS/taro-doctor/blob/main/assets/config_schema.json */
206
- export interface IProjectConfig {
206
+ export interface IProjectConfig<T extends CompilerTypes = CompilerWebpackTypes> {
207
207
  /** 项目名称 */
208
208
  projectName?: string
209
209
 
@@ -295,23 +295,23 @@ export interface IProjectConfig {
295
295
  /** 使用的开发框架。可选值:react、preact、nerv、vue、vue3 */
296
296
  framework?: 'react' | 'preact' | 'nerv' | 'vue' | 'vue3'
297
297
 
298
- /** 使用的编译工具。可选值:webpack4、webpack5 */
299
- compiler?: Compiler
300
-
301
298
  /** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
302
299
  cache?: ICache
303
300
 
304
301
  /** 控制 Taro 编译日志的输出方式 */
305
302
  logger?: ILogger
306
303
 
307
- /** 专属于小程序的配置 */
308
- mini?: IMiniAppConfig
304
+ /** 使用的编译工具。可选值:webpack4、webpack5、vite */
305
+ compiler?: Compiler<T>
309
306
 
310
307
  /** 专属于 H5 的配置 */
311
- h5?: IH5Config
308
+ h5?: IH5Config<T>
309
+
310
+ /** 专属于小程序的配置 */
311
+ mini?: IMiniAppConfig<T>
312
312
 
313
313
  /** 专属于 RN 的配置 */
314
314
  rn?: IRNConfig
315
315
 
316
316
  [key: string]: any
317
- }
317
+ }
@@ -1,4 +1,7 @@
1
- import { type Input } from 'postcss'
1
+ import { type } from 'os'
2
+ import type { Input } from 'postcss'
3
+
4
+ import type { Options as PostcssUrlOption } from 'postcss-url'
2
5
 
3
6
  export type Func = (...args: any[]) => any
4
7
 
@@ -9,6 +12,11 @@ export type TogglableOptions<T = IOption> = {
9
12
  config?: T
10
13
  }
11
14
 
15
+ export interface IUrlLoaderOption extends IOption {
16
+ limit?: number | boolean
17
+ name?: ((moduleId: string) => string) | string
18
+ }
19
+
12
20
  export namespace PostcssOption {
13
21
  export type cssModules = TogglableOptions<{
14
22
  /** 转换模式,取值为 global/module */
@@ -16,10 +24,7 @@ export namespace PostcssOption {
16
24
  /** 自定义生成的class名称规则 */
17
25
  generateScopedName: string | ((localName: string, absoluteFilePath: string) => string)
18
26
  }>
19
- export type url = TogglableOptions<{
20
- limit: number
21
- basePath?: string | string[]
22
- }>
27
+ export type url = TogglableOptions<PostcssUrlOption>
23
28
  }
24
29
 
25
30
  export interface IHtmlTransformOption {
@@ -72,18 +77,27 @@ export interface IPxTransformOption {
72
77
  designWidth?: number | ((size?: string | number | Input) => number)
73
78
  /** 设计稿尺寸换算规则 */
74
79
  deviceRatio?: TaroGeneral.TDeviceRatio
80
+ /** 平台 */
81
+ platform?: 'weapp' | 'h5' | string
82
+ /** fliter 回调函数,可 exclude 不处理的文件 */
83
+ exclude?: (fileName: string) => boolean
75
84
  }
76
85
 
77
- export interface IPostcssOption {
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' | 'mini'> = T extends 'H5'
96
+ ? IBasePostcssOption & { url?: PostcssOption.url }
97
+ : IBasePostcssOption
98
+
99
+ export type Conifg = ViteConfg | WebpackConfig
100
+
87
101
  export interface ICopyOptions {
88
102
  patterns: {
89
103
  from: string
@@ -1,7 +1,10 @@
1
1
  import type { AppConfig, PageConfig } from "../index"
2
2
  import type { IMiniFilesConfig, IH5Config, IMiniAppConfig } from "./config"
3
- import type { IProjectBaseConfig } from './config/project'
3
+ import type { IProjectConfig } from './config/project'
4
4
  import type { PluginContext } from "rollup"
5
+ import { IComponentConfig } from "./hooks"
6
+
7
+ import type { RecursiveTemplate, UnRecursiveTemplate } from '@tarojs/shared/dist/template'
5
8
 
6
9
  export interface ViteNativeCompMeta {
7
10
  name: string
@@ -40,12 +43,12 @@ export interface VitePageMeta {
40
43
  }
41
44
 
42
45
 
43
- export interface ViteH5BuildConfig extends CommonBuildConfig, IH5Config {
46
+ export interface ViteH5BuildConfig extends CommonBuildConfig, IH5Config<'vite'> {
44
47
  entryFileName?: string
45
48
  runtimePath?: string | string[]
46
49
  }
47
50
 
48
- export interface CommonBuildConfig extends IProjectBaseConfig {
51
+ export interface CommonBuildConfig extends IProjectConfig<'vite'> {
49
52
  entry: {
50
53
  app: string | string[]
51
54
  }
@@ -60,7 +63,7 @@ export interface CommonBuildConfig extends IProjectBaseConfig {
60
63
  }
61
64
 
62
65
 
63
- export interface ViteMiniBuildConfig extends CommonBuildConfig, IMiniAppConfig {
66
+ export interface ViteMiniBuildConfig extends CommonBuildConfig, IMiniAppConfig<'vite'> {
64
67
  isBuildPlugin: boolean
65
68
  isSupportRecursive: boolean
66
69
  isSupportXS: boolean
@@ -84,6 +87,7 @@ export interface ViteCompilerContext<T> {
84
87
  cwd: string
85
88
  sourceDir: string
86
89
  taroConfig: T
90
+ rawTaroConfig: T
87
91
  frameworkExts: string[]
88
92
  app: ViteAppMeta
89
93
  pages: VitePageMeta[]