@tarojs/taro 3.7.0-alpha.15 → 3.7.0-alpha.18

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.15",
3
+ "version": "3.7.0-alpha.18",
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.15",
25
- "@tarojs/runtime": "3.7.0-alpha.15"
24
+ "@tarojs/api": "3.7.0-alpha.18",
25
+ "@tarojs/runtime": "3.7.0-alpha.18"
26
26
  },
27
27
  "devDependencies": {
28
- "@tarojs/helper": "3.7.0-alpha.15"
28
+ "@tarojs/helper": "3.7.0-alpha.18",
29
+ "@tarojs/shared": "3.7.0-alpha.18"
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
  },
@@ -20,7 +20,6 @@ interface IPrebundle {
20
20
  interface ICompiler {
21
21
  type: CompilerTypes
22
22
  prebundle?: IPrebundle
23
- vitePlugins?: any[]
24
23
  }
25
24
 
26
25
  export type Compiler = CompilerTypes | ICompiler
@@ -2,7 +2,7 @@ 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
7
 
8
8
  export interface IH5RouterConfig {
@@ -17,7 +17,7 @@ export interface IH5RouterConfig {
17
17
  forcePath?: string
18
18
  }
19
19
 
20
- export interface IH5Config {
20
+ export interface IH5Config <T = 'webapck' | 'vite'> {
21
21
  /** 设置输出解析文件的目录(默认值:'/')*/
22
22
  publicPath?: string
23
23
 
@@ -36,11 +36,9 @@ export interface IH5Config {
36
36
  */
37
37
  webpackChain?: (chain: Chain, webpack: typeof Webpack) => void
38
38
 
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
39
+ /** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/) */
40
+ /** vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/) */
41
+ output?: T extends 'vite' ? Pick<RollupOutputOptions, 'chunkFileNames' | 'assetFileNames' > : Webpack.Configuration['output']
44
42
 
45
43
  /** 路由相关的配置 */
46
44
  router?: IH5RouterConfig
@@ -83,13 +81,13 @@ export interface IH5Config {
83
81
  stylusLoaderOption?: IOption
84
82
 
85
83
  /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
86
- mediaUrlLoaderOption?: IOption
84
+ mediaUrlLoaderOption?: IUrlLoaderOption
87
85
 
88
86
  /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
89
- fontUrlLoaderOption?: IOption
87
+ fontUrlLoaderOption?: IUrlLoaderOption
90
88
 
91
89
  /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
92
- imageUrlLoaderOption?: IOption
90
+ imageUrlLoaderOption?: IUrlLoaderOption
93
91
 
94
92
  /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
95
93
  miniCssExtractPluginOption?: IOption
@@ -104,7 +102,7 @@ export interface IH5Config {
104
102
  useDeprecatedAdapterComponent?: boolean
105
103
 
106
104
  /** 配置 postcss 相关插件 */
107
- postcss?: IPostcssOption
105
+ postcss?: IPostcssOption<'H5'>
108
106
 
109
107
  /** html-webpack-plugin 的具体配置 */
110
108
  htmlPluginOption?: HtmlWebpackPlugin.Options
@@ -1,6 +1,7 @@
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'
4
5
 
5
6
  interface Runtime {
6
7
  enableInnerHTML: boolean
@@ -12,7 +13,22 @@ interface Runtime {
12
13
  enableMutationObserver: boolean
13
14
  }
14
15
 
15
- export interface IMiniAppConfig {
16
+ interface OutputExt {
17
+ /**
18
+ * 编译前清空输出目录
19
+ * @since Taro v3.6.9
20
+ * @description
21
+ * - 默认清空输出目录,可设置 clean: false 不清空
22
+ * - 可设置 clean: { keep: ['project.config.json'] } 保留指定文件
23
+ * - 注意 clean.keep 不支持函数
24
+ */
25
+ clean?: boolean | {
26
+ /** 保留指定文件不删除 */
27
+ keep?: Array<string | RegExp> | string | RegExp
28
+ }
29
+ }
30
+
31
+ export interface IMiniAppConfig<T = 'webpack' | 'vite'> {
16
32
  /** 默认值:'cheap-module-source-map', 具体参考[Webpack devtool 配置](https://webpack.js.org/configuration/devtool/#devtool) */
17
33
  sourceMapType?: string
18
34
 
@@ -37,24 +53,14 @@ export interface IMiniAppConfig {
37
53
  */
38
54
  webpackChain?: (chain: Chain, webpack: typeof Webpack, PARSE_AST_TYPE: any) => void
39
55
 
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
- }
56
+ /** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/)
57
+ vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 这个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/) */
58
+ output?: T extends 'vite'
59
+ ? Pick<RollupOutputOptions, 'chunkFileNames'> & OutputExt
60
+ : Webpack.Configuration['output'] & OutputExt
55
61
 
56
62
  /** 配置 postcss 相关插件 */
57
- postcss?: IPostcssOption
63
+ postcss?: IPostcssOption<'mini'>
58
64
 
59
65
  /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */
60
66
  cssLoaderOption?: IOption
@@ -69,13 +75,13 @@ export interface IMiniAppConfig {
69
75
  stylusLoaderOption?: IOption
70
76
 
71
77
  /** 针对 mp4 | webm | ogg | mp3 | wav | flac | aac 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
72
- mediaUrlLoaderOption?: IOption
78
+ mediaUrlLoaderOption?: IUrlLoaderOption
73
79
 
74
80
  /** 针对 woff | woff2 | eot | ttf | otf 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
75
- fontUrlLoaderOption?: IOption
81
+ fontUrlLoaderOption?: IUrlLoaderOption
76
82
 
77
83
  /** 针对 png | jpg | jpeg | gif | bpm | svg 文件的 [url-loader](https://github.com/webpack-contrib/url-loader) 配置 */
78
- imageUrlLoaderOption?: IOption
84
+ imageUrlLoaderOption?: IUrlLoaderOption
79
85
 
80
86
  /** [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 的附加配置 */
81
87
  miniCssExtractPluginOption?: IOption
@@ -7,6 +7,7 @@ import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from './ut
7
7
  import type { IH5Config } from './h5'
8
8
  import type { IMiniAppConfig, IMiniFilesConfig } from './mini'
9
9
  import type { IRNConfig } from './rn'
10
+ import type { IPrebundle } from '../compiler'
10
11
 
11
12
  export type PluginItem<T = object> = string | [string, T] | [string, () => T | Promise<T>]
12
13
 
@@ -203,7 +204,9 @@ export interface IProjectBaseConfig {
203
204
  }
204
205
 
205
206
  /** 暴露出来给 config/index 使用的配置类型,参考 https://github.com/NervJS/taro-doctor/blob/main/assets/config_schema.json */
206
- export interface IProjectConfig {
207
+
208
+
209
+ interface IBaseProjectConfig {
207
210
  /** 项目名称 */
208
211
  projectName?: string
209
212
 
@@ -295,7 +298,7 @@ export interface IProjectConfig {
295
298
  /** 使用的开发框架。可选值:react、preact、nerv、vue、vue3 */
296
299
  framework?: 'react' | 'preact' | 'nerv' | 'vue' | 'vue3'
297
300
 
298
- /** 使用的编译工具。可选值:webpack4、webpack5 */
301
+ /** 使用的编译工具。可选值:webpack4、webpack5、vite */
299
302
  compiler?: Compiler
300
303
 
301
304
  /** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
@@ -304,14 +307,33 @@ export interface IProjectConfig {
304
307
  /** 控制 Taro 编译日志的输出方式 */
305
308
  logger?: ILogger
306
309
 
307
- /** 专属于小程序的配置 */
308
- mini?: IMiniAppConfig
309
-
310
- /** 专属于 H5 的配置 */
311
- h5?: IH5Config
312
-
313
310
  /** 专属于 RN 的配置 */
314
311
  rn?: IRNConfig
315
312
 
316
313
  [key: string]: any
317
314
  }
315
+
316
+
317
+ export interface IViteProjectConfig extends IBaseProjectConfig {
318
+ compiler?: 'vite' | {
319
+ type: 'vite'
320
+ prebundle?: IPrebundle
321
+ vitePlugins?: any[]
322
+ }
323
+
324
+ /** 专属于 H5 的配置 */
325
+ h5?: IH5Config<'vite'>
326
+
327
+ /** 专属于小程序的配置 */
328
+ mini?: IMiniAppConfig<'vite'>
329
+ }
330
+
331
+ interface IWebpackProjectConfig extends IBaseProjectConfig {
332
+ /** 专属于 H5 的配置 */
333
+ h5?: IH5Config<'webpack'>
334
+
335
+ /** 专属于小程序的配置 */
336
+ mini?: IMiniAppConfig<'webpack'>
337
+ }
338
+
339
+ export type IProjectConfig = IWebpackProjectConfig | IViteProjectConfig
@@ -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 { IViteProjectConfig } 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 IViteProjectConfig {
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,8 @@ export interface ViteCompilerContext<T> {
84
87
  cwd: string
85
88
  sourceDir: string
86
89
  taroConfig: T
90
+ rawTaroConfig: T
91
+ processConfig: () => void
87
92
  frameworkExts: string[]
88
93
  app: ViteAppMeta
89
94
  pages: VitePageMeta[]