diff --git a/.github/workflows/dependabot-update-lockfile.yml b/.github/workflows/dependabot-update-lockfile.yml index f5eab4578c02..f1cda8766902 100644 --- a/.github/workflows/dependabot-update-lockfile.yml +++ b/.github/workflows/dependabot-update-lockfile.yml @@ -27,6 +27,7 @@ jobs: version: 7 run_install: | - recursive: true + args: [--no-frozen-lockfile] - run: | git add pnpm-lock.yaml git commit -m "build(deps-dev): update pnpm-lock.yaml" diff --git a/packages/taro-components/types/Button.d.ts b/packages/taro-components/types/Button.d.ts index c1d3aa1fd1d9..5098ba04b20a 100644 --- a/packages/taro-components/types/Button.d.ts +++ b/packages/taro-components/types/Button.d.ts @@ -203,7 +203,6 @@ interface ButtonProps extends StandardProps { * 当点击按钮时触发。 * event.detail = { followStatus },followStatus 合法值有 1、2、3,其中 1 表示已关注。2 表示用户不允许关注。3 表示发生未知错误; * 已知问题:基础库 1.0,当用户在点击按钮前已关注生活号,event.detail.followStatus 的值为 true。 - * 版本要求:基础库 1.11.0 及以上 * @supported alipay */ onFollowLifestyle?: CommonEventFunction<{ diff --git a/packages/taro-components/types/Canvas.d.ts b/packages/taro-components/types/Canvas.d.ts index 4a2f8c5071f9..dc8dc22b01d0 100644 --- a/packages/taro-components/types/Canvas.d.ts +++ b/packages/taro-components/types/Canvas.d.ts @@ -63,16 +63,6 @@ interface CanvasProps extends StandardProps { */ id?: string - /** - - * @supported alipay - */ - style?: string - - /** - - * @supported alipay - */ - class?: string - /** * @supported alipay */ @@ -89,7 +79,6 @@ interface CanvasProps extends StandardProps { onTap?: CommonEventFunction /** canvas 组件初始化成功触发。 - * 版本要求:基础库 2.7.0 及以上 * @supported alipay */ onReady?: CommonEventFunction diff --git a/packages/taro-components/types/CoverImage.d.ts b/packages/taro-components/types/CoverImage.d.ts index 721b76bb7197..bb6f672a7486 100644 --- a/packages/taro-components/types/CoverImage.d.ts +++ b/packages/taro-components/types/CoverImage.d.ts @@ -22,7 +22,6 @@ interface CoverImageProps extends StandardProps { referrerPolicy?: 'origin' | 'no-referrer' /** 点击事件回调。 - * 版本要求: 基础库 1.9.0 及以上 * @supported alipay */ onTap?: CommonEventFunction diff --git a/packages/taro-components/types/CoverView.d.ts b/packages/taro-components/types/CoverView.d.ts index 7bba5a7400f2..7aecbf684873 100644 --- a/packages/taro-components/types/CoverView.d.ts +++ b/packages/taro-components/types/CoverView.d.ts @@ -8,7 +8,6 @@ interface CoverViewProps extends ViewProps { scrollTop?: number /** 点击事件回调。 - * 版本要求:基础库 1.9.0 及以上 * @supported alipay */ onTap?: CommonEventFunction diff --git a/packages/taro-components/types/Image.d.ts b/packages/taro-components/types/Image.d.ts index e266b18d2d7e..a38d958643ed 100644 --- a/packages/taro-components/types/Image.d.ts +++ b/packages/taro-components/types/Image.d.ts @@ -58,18 +58,7 @@ interface ImageProps extends StandardProps { */ nativeProps?: Record - /** 外部样式。 - * @supported alipay - */ - class?: string - - /** 内联样式。 - * @supported alipay - */ - style?: string - /** 默认图片地址,若设置默认图片地址,会先显示默认图片,等 src 对应的图片加载成功后,再渲染对应的图片。 - * 版本要求: 基础库 1.19.0 及以上 * @supported alipay */ defaultSource?: string diff --git a/packages/taro-components/types/Input.d.ts b/packages/taro-components/types/Input.d.ts index d094211959b1..b2881273995d 100644 --- a/packages/taro-components/types/Input.d.ts +++ b/packages/taro-components/types/Input.d.ts @@ -202,7 +202,6 @@ interface InputProps extends StandardProps, FormItemProps { name?: string /** 是否强制使用系统键盘和 Web-view 创建的 input 元素。为 true 时,confirm-type、confirm-hold 可能失效。 - * 版本要求:基础库 2.7.3 及以上 * @supported alipay */ alwaysSystem?: string diff --git a/packages/taro-components/types/Map.d.ts b/packages/taro-components/types/Map.d.ts index e076f0a6836b..a9128457580b 100644 --- a/packages/taro-components/types/Map.d.ts +++ b/packages/taro-components/types/Map.d.ts @@ -234,19 +234,7 @@ interface MapProps extends StandardProps { */ onAnchorPointTap?: CommonEventFunction - /** 内联样式。 - * @supported alipay - */ - style?: string - - /** 样式名。 - * @supported alipay - */ - class?: string - /** 覆盖物,多边形。 - * - * 版本要求:基础库 1.10.0 及以上 * @supported alipay */ polygon?: string @@ -255,37 +243,21 @@ interface MapProps extends StandardProps { * * default:默认样式 * light:精简样式 - * - * 版本要求:基础库 1.20.0 及以上 * @supported alipay */ customMapStyle?: string /** 基于 map 高级定制渲染,设置覆盖在地图上的 view。 - * - * 版本要求:基础库 1.23.0 及以上 * @supported alipay */ panels?: string /** 点击 panel 时触发。 - * - * { - * - *    panelId, - * - *    layoutId, - * - * } - * - * 版本要求:基础库 1.23.0 及以上 * @supported alipay */ - onPanelTap?: CommonEventFunction + onPanelTap?: CommonEventFunction<{ panelId, layoutId }> /** 地图初始化完成即将开始渲染第一帧时触发。 - * - * 版本要求:基础库 2.7.2 及以上 * @supported alipay */ onInitComplete?: CommonEventFunction diff --git a/packages/taro-components/types/MovableView.d.ts b/packages/taro-components/types/MovableView.d.ts index 6c2d61f0fcf6..5d047f8c634f 100644 --- a/packages/taro-components/types/MovableView.d.ts +++ b/packages/taro-components/types/MovableView.d.ts @@ -112,13 +112,11 @@ interface MovableViewProps extends Omit { onScale?: CommonEventFunction /** 触摸动作开始,事件会向父节点传递。 - * 版本要求: 基础库 1.11.5 及以上 * @supported alipay */ onTouchStart?: CommonEventFunction - /** 触摸移动事件,事件会向父节点传递。 - * 版本要求: 基础库 1.11.5 及以上 + /** 触摸动作开始,事件仅作用于组件,不向父节点传递。 * @supported alipay */ onTouchMove?: CommonEventFunction @@ -144,8 +142,7 @@ interface MovableViewProps extends Omit { */ onVTouchMove?: TouchEventFunction - /** 触摸动作开始,事件仅作用于组件,不向父节点传递。 - * 版本要求: 基础库 1.11.5 及以上 + /** 触摸移动事件,事件仅作用于组件,不向父节点传递。 * @supported alipay */ catchTouchStart?: CommonEventFunction diff --git a/packages/taro-components/types/NavigationBar.d.ts b/packages/taro-components/types/NavigationBar.d.ts index 9909ad466cc3..5d969da7a08a 100644 --- a/packages/taro-components/types/NavigationBar.d.ts +++ b/packages/taro-components/types/NavigationBar.d.ts @@ -37,7 +37,7 @@ interface NavigationBarProps extends StandardProps { /** 页面导航条配置节点,用于指定导航栏的一些属性。只能是 PageMeta 组件内的第一个节点,需要配合它一同使用。 * 通过这个节点可以获得类似于调用 Taro.setNavigationBarTitle Taro.setNavigationBarColor 等接口调用的效果。 * @supported weapp - * @see https://developers.weixin.qq.com/miniprogram/dev/component/open-data.html + * @see https://developers.weixin.qq.com/miniprogram/dev/component/navigation-bar.html */ declare const NavigationBar: ComponentType export { NavigationBar, NavigationBarProps } diff --git a/packages/taro-components/types/PickerView.d.ts b/packages/taro-components/types/PickerView.d.ts index 905833eb69df..a8845a3f5e93 100644 --- a/packages/taro-components/types/PickerView.d.ts +++ b/packages/taro-components/types/PickerView.d.ts @@ -58,13 +58,11 @@ interface PickerViewProps extends StandardProps { ariaLabel?: string /** 当滚动选择开始时候触发事件。 - * 版本要求: 基础库 2.7.23 及以上 * @supported alipay */ onPickerStart?: CommonEventFunction /** 当滚动选择结束时候触发事件。 - * 版本要求: 基础库 2.7.23 及以上 * @supported alipay */ onPickerEnd?: CommonEventFunction diff --git a/packages/taro-components/types/ScrollView.d.ts b/packages/taro-components/types/ScrollView.d.ts index 71add8652a4f..42500add2b62 100644 --- a/packages/taro-components/types/ScrollView.d.ts +++ b/packages/taro-components/types/ScrollView.d.ts @@ -176,61 +176,43 @@ interface ScrollViewProps extends StandardProps { */ onDragend?: CommonEventFunction - /** 外部样式名。 - * @supported alipay - */ - class?: string - - /** 内联样式名。 - * @supported alipay - */ - style?: string - /** 当 scroll-with-animation设置为 true 时,可以设置 scroll-animation-duration 来控制动画的执行时间,单位 ms。 - * 版本要求: 基础库 1.9.0 及以上 * @supported alipay */ scrollAnimationDuration?: string /** 纵向滚动时,当滚动到顶部或底部时,强制禁止触发页面滚动,仍然只触发 scroll-view 自身的滚动。 - * 默认值: false - * 版本要求: 基础库 1.11.2 及以上 * @supported alipay + * @default false */ trapScroll?: string /** 触摸动作开始。 - * 版本要求: 基础库 1.15.0 及以上 * @supported alipay */ onTouchStart?: CommonEventFunction /** 触摸后移动。 - * 版本要求: 基础库 1.15.0 及以上 * @supported alipay */ onTouchMove?: CommonEventFunction /** 触摸动作结束。 - * 版本要求: 基础库 1.15.0 及以上 * @supported alipay */ onTouchEnd?: CommonEventFunction /** 触摸动作被打断,如来电提醒、弹窗。 - * 版本要求: 基础库 1.15.0 及以上 * @supported alipay */ onTouchCancel?: CommonEventFunction /** 发生滚动前,对滚动方向进行判断,当方向是顶部/左边时,如果值为 always 将始终禁止滚动,如果值为 out-of-bounds 且当前已经滚动到顶部/左边,禁止滚动。 - * 版本要求:基础库 2.6.2 及以上 * @supported alipay */ disableLowerScroll?: string /** 发生滚动前,对滚动方向进行判断,当方向是底部/右边时,如果值为 always 将始终禁止滚动,如果值为 out-of-bounds 且当前已经滚动到底部/右边,禁止滚动。 - * 版本要求:基础库 2.6.2 及以上 * @supported alipay */ disableUpperScroll?: string diff --git a/packages/taro-components/types/Swiper.d.ts b/packages/taro-components/types/Swiper.d.ts index 00776f0901ee..a6741dc39a9d 100644 --- a/packages/taro-components/types/Swiper.d.ts +++ b/packages/taro-components/types/Swiper.d.ts @@ -119,26 +119,22 @@ interface SwiperProps extends StandardProps { disableTouch?: boolean /** swiper-item 可见时的 class。 - * 版本要求: 基础库 1.13.7 以及上。 * @supported alipay */ activeClass?: string /** acceleration 设置为 {{true}} 时且处于滑动过程中,中间若干屏处于可见时的 class。 - * 版本要求: 基础库 1.13.7 以及上。 * @supported alipay */ changingClass?: string /** 当开启时,会根据滑动速度,连续滑动多屏。 - * 版本要求: 基础库 1.13.7 及以上 * @default false * @supported alipay */ acceleration?: string /** 是否禁用代码变动触发 swiper 切换时使用动画。 - * 版本要求: 基础库 1.13.7 及以上 * @default false * @supported alipay */ @@ -150,31 +146,26 @@ interface SwiperProps extends StandardProps { onAnimationEnd?: CommonEventFunction /** 滑动距离阈值,当滑动距离超过阈值时进行 swiper-item 切换。 - * 版本要求:基础库 1.24.11 及以上 * @supported alipay */ swipeRatio?: string /** 滑动综合速度阈值,当超过阈值时进行 swiper-item 切换,数值越小越敏感。 - * 版本要求:基础库 1.24.11 及以上 * @supported alipay */ swipeSpeed?: string /** 计算用户手势时所依赖的滑动角度。角度根据 touchstart 事件和首次 touchmove 事件的坐标计算得出。数值越小越对用户的滑动方向准确度要求越高。 - * 版本要求:基础库 1.24.11 及以上 * @supported alipay */ touchAngle?: string /** 自动以指定滑块的高度为整个容器的高度。当 vertical 为 true 时,默认不调整。可选值为: - * 版本要求:基础库 2.6.4 及以上 * @supported alipay */ adjustHeight?: 'first' | 'current' | 'highest' | 'none' /** vertical 为 true 时强制使 adjust-height 生效。 - * 版本要求:基础库 2.6.4 及以上 * @supported alipay */ adjustVerticalHeight?: string diff --git a/packages/taro-components/types/Switch.d.ts b/packages/taro-components/types/Switch.d.ts index 6bb9fefc7d24..0cf24d452b4e 100644 --- a/packages/taro-components/types/Switch.d.ts +++ b/packages/taro-components/types/Switch.d.ts @@ -41,7 +41,6 @@ interface SwitchProps extends StandardProps, FormItemProps { name?: string /** 是否为受控组件,为 true 时,checked 会完全受 setData 控制。 - * 版本要求: 基础库 1.8.0 及以上 * @default false * @supported alipay */ diff --git a/packages/taro-components/types/Textarea.d.ts b/packages/taro-components/types/Textarea.d.ts index d3289389e625..12b24e560345 100644 --- a/packages/taro-components/types/Textarea.d.ts +++ b/packages/taro-components/types/Textarea.d.ts @@ -159,13 +159,11 @@ interface TextareaProps extends StandardProps, FormItemProps { name?: string /** 是否渲染字数统计功能(是否删除默认计数器/是否显示字数统计)。 - * 版本要求: 基础库 1.8.0 及以上 * @supported alipay */ showCount?: string /** 是否为受控组件。为 true 时,value 内容会完全受 setData 控制。 - * 版本要求: 基础库 1.8.0 及以上 * @supported alipay */ controlled?: string diff --git a/packages/taro-components/types/Video.d.ts b/packages/taro-components/types/Video.d.ts index 2bccb4e72ed8..14e0951b8b4c 100644 --- a/packages/taro-components/types/Video.d.ts +++ b/packages/taro-components/types/Video.d.ts @@ -336,23 +336,12 @@ interface VideoProps extends StandardProps { */ onControlsToggle?: CommonEventFunction - /** 内联样式。 - * @supported alipay - */ - style?: string - - /** 外部样式名。 - * @supported alipay - */ - class?: string - /** 当 poster 高宽比跟视频高宽不匹配时,如何显示 poster,设置规则同 background-size 一致。 * @supported alipay */ posterSize?: string /** 当底部工具条隐藏时,是否显示细进度条(controls=false 时设置无效)。 - * 版本要求: 基础库 1.15.0 及以上 * @supported alipay */ showThinProgressBar?: string @@ -364,7 +353,6 @@ interface VideoProps extends StandardProps { * 2 - 阻塞提醒(无消耗流量大小) * 3 - 阻塞提醒(有消耗流量大小提醒) * - * 版本要求: 基础库 1.13.0 及以上 * @supported alipay, jd */ mobilenetHintType?: string @@ -385,13 +373,11 @@ interface VideoProps extends StandardProps { onUserAction?: CommonEventFunction /** 视频播放终止。 - * 版本要求: 基础库 1.9.0 及以上 * @supported alipay */ onStop?: CommonEventFunction /** 当视频加载完真正开始播放时触发。 - * 版本要求: 基础库 1.13.6 及以上 * @supported alipay */ onRenderStart?: CommonEventFunction @@ -401,7 +387,6 @@ interface VideoProps extends StandardProps { * * none:无浮窗。 * page:页面内浮窗。 - * 版本要求:基础库 1.24.6 及以上 * @supported alipay */ floatingMode?: string diff --git a/packages/taro-components/types/View.d.ts b/packages/taro-components/types/View.d.ts index d912c1fbe579..9019e666cf48 100644 --- a/packages/taro-components/types/View.d.ts +++ b/packages/taro-components/types/View.d.ts @@ -34,7 +34,6 @@ interface ViewProps extends StandardProps { hoverStayTime?: number /** 是否阻止区域内滚动页面。 - * 默认值: false * 说明: 如果 view 中嵌套 view,外层 view 设置 disable-scroll 为 true 时禁止内部的滚动。 * @supported alipay * @default false @@ -42,25 +41,14 @@ interface ViewProps extends StandardProps { disableScroll?: string /** 是否隐藏。 - * 默认值: false * @supported alipay * @default false */ hidden?: boolean - /** 自定义样式名。 - * @supported alipay - */ - class?: string - - /** 内联样式。 - * @supported alipay - */ - style?: string - /** 用于动画,详见 my.createAnimation 。使用 my.createAnimation 生成的动画是通过过渡(Transition)实现的,只会触发 onTransitionEnd,不会触发 onAnimationStart, onAnimationIteration, onAnimationEnd。 - * 默认值:{} * @supported alipay + * @default {} */ animation?: TaroGeneral.IAnyObject @@ -95,43 +83,36 @@ interface ViewProps extends StandardProps { onLongTap?: CommonEventFunction /** 过渡(Transition)结束时触发。 - * 版本要求: 基础库 1.8.0 及以上 * @supported alipay */ onTransitionEnd?: CommonEventFunction /** 每开启一次新的动画过程时触发。(第一次不触发) - * 版本要求: 基础库 1.8.0 及以上 * @supported alipay */ onAnimationIteration?: CommonEventFunction /** 动画开始时触发。 - * 版本要求: 基础库 1.8.0 及以上 * @supported alipay */ onAnimationStart?: CommonEventFunction /** 动画结束时触发。 - * 版本要求: 基础库 1.8.0 及以上 * @supported alipay */ onAnimationEnd?: CommonEventFunction /** 当前元素可见面积超过50%时触发。 - * 版本要求: 基础库 1.9.0 及以上 * @supported alipay */ onAppear?: CommonEventFunction /** 当前元素不可见面积超过50%时触发。 - * 版本要求: 基础库 1.9.0 及以上 * @supported alipay */ onDisappear?: CommonEventFunction /** 当前元素首次可见面积达到50%时触发。 - * 版本要求: 基础库 1.9.4 及以上 * @supported alipay */ onFirstAppear?: CommonEventFunction diff --git a/packages/taro-mini-runner/src/index.ts b/packages/taro-mini-runner/src/index.ts index 4bea9637d6af..203483668a40 100644 --- a/packages/taro-mini-runner/src/index.ts +++ b/packages/taro-mini-runner/src/index.ts @@ -5,10 +5,12 @@ import * as webpack from 'webpack' import { Prerender } from './prerender/prerender' import { componentConfig } from './template/component' import { bindDevLogger, bindProdLogger, printBuildError } from './utils/logHelper' -import { Func, IBuildConfig } from './utils/types' import buildConf from './webpack/build.conf' import { makeConfig } from './webpack/chain' +import type { Func } from '@tarojs/taro/types/compile' +import type { IBuildConfig } from './utils/types' + const customizeChain = async (chain, modifyWebpackChainFunc: Func, customizeFunc?: Func) => { if (modifyWebpackChainFunc instanceof Function) { await modifyWebpackChainFunc(chain, webpack, { @@ -30,7 +32,7 @@ export default async function build (appPath: string, config: IBuildConfig): Pro const webpackChain = buildConf(appPath, mode, newConfig) /** customized chain */ - await customizeChain(webpackChain, newConfig.modifyWebpackChain, newConfig.webpackChain) + await customizeChain(webpackChain, newConfig.modifyWebpackChain!, newConfig.webpackChain) if (typeof newConfig.onWebpackChainReady === 'function') { newConfig.onWebpackChainReady(webpackChain) diff --git a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts index 8d66426ebe1c..e6c1b1b8204f 100644 --- a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts +++ b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts @@ -13,8 +13,6 @@ import { resolveMainFilePath, SCRIPT_EXT } from '@tarojs/helper' -import { RecursiveTemplate, UnRecursiveTemplate } from '@tarojs/shared/dist/template' -import { AppConfig, Config } from '@tarojs/taro' import * as fs from 'fs-extra' import { minify } from 'html-minifier' import { urlToRequest } from 'loader-utils' @@ -34,11 +32,15 @@ import { ConcatSource } from 'webpack-sources' import TaroSingleEntryDependency from '../dependencies/TaroSingleEntryDependency' import { PrerenderConfig, validatePrerenderPages } from '../prerender/prerender' import { componentConfig } from '../template/component' -import { AddPageChunks, Func, IComponent, IFileType } from '../utils/types' import TaroLoadChunksPlugin from './TaroLoadChunksPlugin' import TaroNormalModulesPlugin from './TaroNormalModulesPlugin' import TaroSingleEntryPlugin from './TaroSingleEntryPlugin' +import type { RecursiveTemplate, UnRecursiveTemplate } from '@tarojs/shared/dist/template' +import type { AppConfig, Config } from '@tarojs/taro' +import type { Func } from '@tarojs/taro/types/compile' +import type { AddPageChunks, IComponent, IFileType } from '../utils/types' + const PLUGIN_NAME = 'TaroMiniPlugin' interface ITaroMiniPluginOptions { diff --git a/packages/taro-mini-runner/src/plugins/TaroNormalModulesPlugin.ts b/packages/taro-mini-runner/src/plugins/TaroNormalModulesPlugin.ts index e4fa87176b08..a742462aba2e 100644 --- a/packages/taro-mini-runner/src/plugins/TaroNormalModulesPlugin.ts +++ b/packages/taro-mini-runner/src/plugins/TaroNormalModulesPlugin.ts @@ -2,9 +2,10 @@ import webpack from 'webpack' import TaroSingleEntryDependency from '../dependencies/TaroSingleEntryDependency' import { componentConfig } from '../template/component' -import { Func } from '../utils/types' import TaroNormalModule from './TaroNormalModule' +import type { Func } from '@tarojs/taro/types/compile' + const walk = require('acorn-walk') const PLUGIN_NAME = 'TaroNormalModulesPlugin' diff --git a/packages/taro-mini-runner/src/utils/types.ts b/packages/taro-mini-runner/src/utils/types.ts index 91cc2c610b2a..0df553396f28 100644 --- a/packages/taro-mini-runner/src/utils/types.ts +++ b/packages/taro-mini-runner/src/utils/types.ts @@ -1,9 +1,7 @@ -import { IMiniAppConfig, IProjectBaseConfig } from '@tarojs/taro/types/compile' -import * as webpack from 'webpack' - -import { PrerenderConfig } from '../prerender/prerender' - import type { RecursiveTemplate, UnRecursiveTemplate } from '@tarojs/shared/dist/template' +import type { Func, IMiniAppConfig, IProjectBaseConfig } from '@tarojs/taro/types/compile' +import type * as webpack from 'webpack' +import type { PrerenderConfig } from '../prerender/prerender' type FunctionLikeCustomWebpackConfig = (webpackConfig: webpack.Configuration, webpack) => webpack.Configuration @@ -38,8 +36,6 @@ export interface IFileType { xs?: string } -export type Func = (...args: any[]) => any - export interface IBuildConfig extends IProjectBaseConfig, IMiniAppConfig { blended?: boolean buildAdapter: string diff --git a/packages/taro-webpack-runner/src/config/postcss.conf.ts b/packages/taro-webpack-runner/src/config/postcss.conf.ts index 19a7af0f629d..26d3e0472a6b 100644 --- a/packages/taro-webpack-runner/src/config/postcss.conf.ts +++ b/packages/taro-webpack-runner/src/config/postcss.conf.ts @@ -1,9 +1,8 @@ import { isNpmPkg, recursiveMerge } from '@tarojs/helper' -import { Func } from '@tarojs/runtime' import * as path from 'path' import { sync as resolveSync } from 'resolve' -import type { IPostcssOption, TogglableOptions } from '@tarojs/taro/types/compile' +import type { Func, IPostcssOption, TogglableOptions } from '@tarojs/taro/types/compile' const platform = 'h5' const defaultAutoprefixerOption = { diff --git a/packages/taro-webpack-runner/src/index.ts b/packages/taro-webpack-runner/src/index.ts index 19c2a4fdd080..997d5883fd6c 100644 --- a/packages/taro-webpack-runner/src/index.ts +++ b/packages/taro-webpack-runner/src/index.ts @@ -1,5 +1,4 @@ import { recursiveMerge } from '@tarojs/helper' -import { AppConfig } from '@tarojs/taro' import * as detectPort from 'detect-port' import * as path from 'path' import { format as formatUrl } from 'url' @@ -13,7 +12,10 @@ import prodConf from './config/prod.conf' import { addHtmlSuffix, addLeadingSlash, formatOpenHost, getAppConfig, getAppEntry, parsePublicPath, stripBasename, stripTrailingSlash } from './util' import { makeConfig } from './util/chain' import { bindDevLogger, bindProdLogger, printBuildError } from './util/logHelper' -import { BuildConfig, Func } from './util/types' + +import type { AppConfig } from '@tarojs/taro' +import type { Func } from '@tarojs/taro/types/compile' +import type { BuildConfig } from './util/types' export const customizeChain = async (chain, modifyWebpackChainFunc: Func, customizeFunc?: Func) => { if (modifyWebpackChainFunc instanceof Function) { @@ -26,7 +28,7 @@ export const customizeChain = async (chain, modifyWebpackChainFunc: Func, custom const buildProd = async (appPath: string, config: BuildConfig, appConfig: AppConfig): Promise => { const webpackChain = prodConf(appPath, config, appConfig) - await customizeChain(webpackChain, config.modifyWebpackChain, config.webpackChain) + await customizeChain(webpackChain, config.modifyWebpackChain!, config.webpackChain) if (typeof config.onWebpackChainReady === 'function') { config.onWebpackChainReady(webpackChain) } @@ -76,7 +78,7 @@ const buildDev = async (appPath: string, config: BuildConfig, appConfig: AppConf const { proxy: customProxy = [], ...customDevServerOption } = config.devServer || {} const webpackChain = devConf(appPath, config, appConfig) const onBuildFinish = config.onBuildFinish - await customizeChain(webpackChain, config.modifyWebpackChain, config.webpackChain) + await customizeChain(webpackChain, config.modifyWebpackChain!, config.webpackChain) const isMultiRouterMode = routerMode === 'multi' const proxy: WebpackDevServer.Configuration['proxy'] = [] diff --git a/packages/taro-webpack5-runner/src/index.h5.ts b/packages/taro-webpack5-runner/src/index.h5.ts index 7e497b9e93f7..139b47a9e13d 100644 --- a/packages/taro-webpack5-runner/src/index.h5.ts +++ b/packages/taro-webpack5-runner/src/index.h5.ts @@ -202,7 +202,7 @@ async function getDevServerOptions (appPath: string, config: H5BuildConfig): Pro })) } - const chunkFilename = config.output.chunkFilename ?? `${config.chunkDirectory || 'chunk'}/[name].js` + const chunkFilename = config.output?.chunkFilename as string ?? `${config.chunkDirectory || 'chunk'}/[name].js` const devServerOptions: WebpackDevServer.Configuration = recursiveMerge( { devMiddleware: { diff --git a/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts b/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts index eecfa2728a5d..4b019ccec96d 100644 --- a/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts +++ b/packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts @@ -12,22 +12,25 @@ import { resolveMainFilePath, SCRIPT_EXT } from '@tarojs/helper' -import { RecursiveTemplate, UnRecursiveTemplate } from '@tarojs/shared/dist/template' -import { AppConfig, Config } from '@tarojs/taro' import fs from 'fs-extra' import { urlToRequest } from 'loader-utils' import path from 'path' -import webpack, { Compilation, Compiler, sources } from 'webpack' +import webpack, { Compilation, sources } from 'webpack' import EntryDependency from 'webpack/lib/dependencies/EntryDependency' import TaroSingleEntryDependency from '../dependencies/TaroSingleEntryDependency' import { PrerenderConfig, validatePrerenderPages } from '../prerender/prerender' import { componentConfig } from '../template/component' -import { AddPageChunks, Func, IComponent, IFileType } from '../utils/types' import TaroLoadChunksPlugin from './TaroLoadChunksPlugin' import TaroNormalModulesPlugin from './TaroNormalModulesPlugin' import TaroSingleEntryPlugin from './TaroSingleEntryPlugin' +import type { RecursiveTemplate, UnRecursiveTemplate } from '@tarojs/shared/dist/template' +import type { AppConfig, Config } from '@tarojs/taro' +import type { Func } from '@tarojs/taro/types/compile' +import type { Compiler } from 'webpack' +import type { AddPageChunks, IComponent, IFileType } from '../utils/types' + const PLUGIN_NAME = 'TaroMiniPlugin' const { ConcatSource, RawSource } = sources diff --git a/packages/taro-webpack5-runner/src/plugins/TaroNormalModulesPlugin.ts b/packages/taro-webpack5-runner/src/plugins/TaroNormalModulesPlugin.ts index f95013b97bcb..dd579c8f7c3c 100644 --- a/packages/taro-webpack5-runner/src/plugins/TaroNormalModulesPlugin.ts +++ b/packages/taro-webpack5-runner/src/plugins/TaroNormalModulesPlugin.ts @@ -1,10 +1,10 @@ -import { Compiler } from 'webpack' - import TaroSingleEntryDependency from '../dependencies/TaroSingleEntryDependency' import { componentConfig } from '../template/component' -import { Func } from '../utils/types' import TaroNormalModule from './TaroNormalModule' +import type { Func } from '@tarojs/taro/types/compile' +import type { Compiler } from 'webpack' + const walk = require('acorn-walk') const PLUGIN_NAME = 'TaroNormalModulesPlugin' diff --git a/packages/taro-webpack5-runner/src/postcss/postcss.h5.ts b/packages/taro-webpack5-runner/src/postcss/postcss.h5.ts index 2f8a76323c92..df61b117dc55 100644 --- a/packages/taro-webpack5-runner/src/postcss/postcss.h5.ts +++ b/packages/taro-webpack5-runner/src/postcss/postcss.h5.ts @@ -1,9 +1,8 @@ import { isNpmPkg, recursiveMerge } from '@tarojs/helper' -import { Func } from '@tarojs/runtime' import path from 'path' import { sync as resolveSync } from 'resolve' -import type { IPostcssOption, TogglableOptions } from '@tarojs/taro/types/compile' +import type { Func, IPostcssOption, TogglableOptions } from '@tarojs/taro/types/compile' const platform = 'h5' const defaultAutoprefixerOption = { diff --git a/packages/taro-webpack5-runner/src/utils/types.ts b/packages/taro-webpack5-runner/src/utils/types.ts index a5492d60e20a..f88c4d884c0a 100644 --- a/packages/taro-webpack5-runner/src/utils/types.ts +++ b/packages/taro-webpack5-runner/src/utils/types.ts @@ -1,7 +1,6 @@ import type { RecursiveTemplate, UnRecursiveTemplate } from '@tarojs/shared/dist/template' import type { IH5Config, IMiniAppConfig, IProjectBaseConfig } from '@tarojs/taro/types/compile' import type Webpack from 'webpack' -import type Chain from 'webpack-chain' import type { PrerenderConfig } from '../prerender/prerender' import type { IComponentConfig } from '../template/component' @@ -35,12 +34,6 @@ export interface IFileType { xs?: string } -export type Func = (...args: any[]) => any - -export interface HookModifyWebpackChain { - (chain: Chain, webpack: typeof Webpack, data: { componentConfig: IComponentConfig }): Promise -} - export interface CommonBuildConfig extends IProjectBaseConfig { entry?: Webpack.EntryObject mode: 'production' | 'development' | 'none' diff --git a/packages/taro-webpack5-runner/src/webpack/H5WebpackModule.ts b/packages/taro-webpack5-runner/src/webpack/H5WebpackModule.ts index 2c44dab93a57..351489f4e47f 100644 --- a/packages/taro-webpack5-runner/src/webpack/H5WebpackModule.ts +++ b/packages/taro-webpack5-runner/src/webpack/H5WebpackModule.ts @@ -7,12 +7,11 @@ import { REG_STYLE, REG_STYLUS } from '@tarojs/helper' -import { Func } from '@tarojs/runtime' import { getDefaultPostcssConfig, getPostcssPlugins } from '../postcss/postcss.h5' import { WebpackModule } from './WebpackModule' -import type { PostcssOption } from '@tarojs/taro/types/compile' +import type { Func, PostcssOption } from '@tarojs/taro/types/compile' import type { H5Combination } from './H5Combination' import type { CssModuleOptionConfig, IRule } from './WebpackModule' diff --git a/packages/taro/types/api/media/image.d.ts b/packages/taro/types/api/media/image.d.ts index dcaea5751ed7..788e42ce58c5 100644 --- a/packages/taro/types/api/media/image.d.ts +++ b/packages/taro/types/api/media/image.d.ts @@ -441,6 +441,6 @@ declare module '../../index' { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.cropImage.html */ - cropImage(option: cropImage.Option): Promise + cropImage(option: cropImage.Option): Promise } } diff --git a/packages/taro/types/compile.d.ts b/packages/taro/types/compile.d.ts deleted file mode 100644 index f849a5e2b798..000000000000 --- a/packages/taro/types/compile.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -import swc from '@swc/core' -export { Current } from '@tarojs/runtime' -import webpack from 'webpack' -import webpackDevServer from 'webpack-dev-server' -import HtmlWebpackPlugin from 'html-webpack-plugin' - -export const enum TEMPLATE_TYPES { - WEAPP = '.wxml', - SWAN = '.swan', - ALIPAY = '.axml', - TT = '.ttml', - QUICKAPP = '.ux', - QQ = '.qml' -} - -export const enum STYLE_TYPES { - WEAPP = '.wxss', - SWAN = '.css', - ALIPAY = '.acss', - TT = '.ttss', - QUICKAPP = '.css', - QQ = '.qss' -} - -export const enum SCRIPT_TYPES { - WEAPP = '.js', - SWAN = '.js', - ALIPAY = '.js', - TT = '.js', - QUICKAPP = '.js', - QQ = '.js' -} - -export const enum CONFIG_TYPES { - WEAPP = '.json', - SWAN = '.json', - ALIPAY = '.json', - TT = '.json', - QUICKAPP = '.json', - QQ = '.json' -} - -export type IMINI_APP_FILE_TYPE = { - TEMPL: TEMPLATE_TYPES, - STYLE: STYLE_TYPES, - SCRIPT: SCRIPT_TYPES, - CONFIG: CONFIG_TYPES -} - -export type IMINI_APP_FILES = { - [key: string]: IMINI_APP_FILE_TYPE -} - -export type IOption = Record - -export interface ICopyOptions { - patterns: { - from: string - to: string - ignore?: string[] - transform?: Function - watch?: boolean - }[] - options: { - ignore?: string[] - } -} - -export interface ISassOptions { - /** - * 引入的全局 sass 文件,如果要引入多个文件,支持数组形式传入 - */ - resource?: string | string[] - /** - * 项目根目录的绝对地址(若为小程序云开发模板,则应该是client目录) - */ - projectDirectory?: string - /** - * 全局 scss 变量,若 data 与 resource 中设置了同样的变量,则 data 的优先级高于 resource - */ - data?: string -} - -export interface ICopyArgOptions { - filter?: (src: string) => boolean -} - -export namespace PostcssOption { - export type cssModules = TogglableOptions<{ - namingPattern: 'global' | string - generateScopedName: string | ((localName: string, absoluteFilePath: string) => string) - }> - export type url = TogglableOptions<{ - limit: number - basePath?: string | string[] - }> -} - -export interface IPostcssOption { - autoprefixer?: TogglableOptions - pxtransform?: TogglableOptions - cssModules?: PostcssOption.cssModules - url?: PostcssOption.url - [key: string]: any -} - -export interface ICompileOption { - exclude?: string[] - include?: string[] -} - -interface Runtime { - enableInnerHTML: boolean - enableSizeAPIs: boolean - enableAdjacentHTML: boolean - enableTemplateContent: boolean - enableCloneNode: boolean - enableContains: boolean - enableMutationObserver: boolean -} - -export interface IMiniAppConfig { - appOutput?: boolean - sourceMapType?: string - debugReact?: boolean - minifyXML?: { - collapseWhitespace?: boolean - } - - webpackChain?: (chain: any, webpack: any, PARSE_AST_TYPE: any) => void - output?: webpack.Output - postcss?: IPostcssOption - cssLoaderOption?: IOption - sassLoaderOption?: IOption - lessLoaderOption?: IOption - stylusLoaderOption?: IOption - mediaUrlLoaderOption?: IOption - fontUrlLoaderOption?: IOption - imageUrlLoaderOption?: IOption - miniCssExtractPluginOption?: IOption - - customFilesTypes?: IMINI_APP_FILE_TYPE - commonChunks?: string[] | ((commonChunks: string[]) => string[]) - addChunkPages?: ((pages: Map, pagesNames?: string[]) => void) - optimizeMainPackage?: { - enable?: boolean - exclude?: any[] - } - - compile?: { - exclude?: any[] - include?: any[] - } - runtime?: Runtime -} - -export type TogglableOptions = { - enable?: boolean - config?: T -} - -export interface IH5RouterConfig { - mode?: 'hash' | 'browser' | 'multi' - customRoutes?: IOption - basename?: string - lazyload?: boolean | ((pagename: string) => boolean) - renamePagename?: (pagename: string) => string - forcePath?: string -} - -export interface IH5Config { - publicPath?: string - staticDirectory?: string - chunkDirectory?: string - - webpack?: ((webpackConfig: webpack.Configuration, webpack) => webpack.Configuration) | webpack.Configuration - - webpackChain?: (chain: any, webpack: any) => void - - output?: webpack.Output - router?: IH5RouterConfig - devServer?: webpackDevServer.Configuration - 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' - enableExtract?: boolean - transformOnly?: boolean - - cssLoaderOption?: IOption - styleLoaderOption?: IOption - sassLoaderOption?: IOption - lessLoaderOption?: IOption - stylusLoaderOption?: IOption - mediaUrlLoaderOption?: IOption - fontUrlLoaderOption?: IOption - imageUrlLoaderOption?: IOption - miniCssExtractPluginOption?: IOption - esnextModules?: string[] - useHtmlComponents?: boolean - - postcss?: IPostcssOption - htmlPluginOption?: HtmlWebpackPlugin.Options -} - -type FeatureItem = { - name: string -} - -declare enum LogLevel { - OFF = 'off', - ERROR = 'error', - WARN = 'warn', - INFO = 'info', - LOG = 'log', - DEBUG = 'debug' -} - -export type SystemConfig = { - /** - * 打印日志等级,分为 off,error,warn,info,log,debug - */ - logLevel?: LogLevel - /** - * 页面设计基准宽度,根据实际设备宽度来缩放元素大小 - */ - designWidth?: number - /** - * 全局数据对象,属性名不能以$或_开头,在页面中可通过 this 进行访问;如果全局数据属性与页面的数据属性重名,则页面初始化时,全局数据会覆盖页面中对应的属性值 - */ - data?: IOption -} - -type RouterConfig = { - /** - * 首页名称 - */ - entry: string - /** - * 页面配置列表,key 值为页面名称(对应页面目录名,例如 Hello 对应'Hello'目录),value 为页面详细配置 page - */ - pages: RouterPage[] -} -type RouterPage = { - /** - * 页面对应的组件名,与 ux 文件名保持一致,例如'hello' 对应 'hello.ux' - */ - component: string - /** - * 页面路径,例如“/user”,不填则默认为/<页面名称>。 - * path 必须唯一,不能和其他 page 的 path 相同。 - * 下面 page 的 path 因为缺失,会被设置为“/Index”: - * "Index": {"component": "index"} - */ - path?: string - /** - * 声明页面可以处理某种请求 - */ - filter: { - [key: string]: { - uri: string - } - } -} - -interface IDefaultDisplayConfig { - /** - * 窗口背景颜色 - */ - backgroundColor?: string - /** - * 是否是全屏模式,默认不会同时作用于 titleBar,titleBar 需要继续通过 titleBar 控制 - */ - fullScreen?: boolean - /** - * 是否显示 titleBar - */ - titleBar?: boolean - /** - * 标题栏背景色 - */ - titleBarBackgroundColor?: string - /** - * 标题栏文字颜色 - */ - titleBarTextColor?: string - /** - * 标题栏文字(也可通过页面跳转传递参数(titleBarText)设置) - */ - titleBarText?: string - /** - * 是否显示标题栏右上角菜单按钮,点击菜单按钮调用页面生命周期 onMenuPress 方法,如果该方法未实现则显示系统默认菜单 - */ - menu?: boolean - /** - * 软键盘弹出时为保证输入框可见,页面的调整方式。 adjustPan:上移页面; adjustResize:压缩页面显示区域,当页面全屏时,此设置不生效 - */ - windowSoftInputMode?: 'adjustPan' | 'adjustResize' -} - -interface IDisplayConfig extends IDefaultDisplayConfig { - /** - * 各个页面的显示样式,key 为页面名(与路由中的页面名保持一致),value 为窗口显示样式,页面样式覆盖 default 样式 - */ - pages?: { - [key: string]: IDefaultDisplayConfig - } -} - -export interface ITaroManifestConfig { - /** - * 应用包名,确认与原生应用的包名不一致,推荐采用 com.company.module 的格式,如:com.example.demo - */ - package: string - /** - * 应用名称,6 个汉字以内,与应用商店保存的名称一致,用于在桌面图标、弹窗等处显示应用名称 - */ - name: string - /** - * 应用图标,提供 192x192 大小的即可 - */ - icon: string - /** - * 应用版本名称,如:"1.0" - */ - versionName?: string - /** - * 应用版本号,从1自增,推荐每次重新上传包时versionCode+1 - */ - versionCode: number - /** - * 支持的最小平台版本号,兼容性检查,避免上线后在低版本平台运行并导致不兼容;如果不填按照内测版本处理 - */ - minPlatformVersion?: string - /** - * 接口列表,绝大部分接口都需要在这里声明,否则不能调用,详见每个接口的文档说明 - */ - features?: FeatureItem[] - /** - * - */ - logLevel?: LogLevel -} - -export interface IManifestConfig extends ITaroManifestConfig { - /** - * 系统配置信息 - */ - config: SystemConfig - /** - * 路由信息 - */ - router: RouterConfig - /** - * UI 显示相关配置 - */ - display?: IDisplayConfig -} - -export type PluginItem = string | [string, object] - -interface ICache { - enable?: boolean - buildDependencies?: Record - name?: string -} - -type CompilerTypes = 'webpack4' | 'webpack5' -interface IPrebundle { - enable?: boolean - timings?: boolean - cacheDir?: string - force?: boolean - include?: string[] - exclude?: string[] - esbuild?: Record - swc?: swc.Config - webpack?: webpack.Configuration & { - provide?: any[] - } -} -interface ICompiler { - type: CompilerTypes - prebundle: IPrebundle -} -type Compiler = CompilerTypes | ICompiler - -interface ILogger { - quiet: boolean - stats: boolean -} - -export interface IProjectBaseConfig { - isWatch?: boolean - port?: number - projectName?: string - date?: string - designWidth?: number - watcher?: any[] - deviceRatio?: TaroGeneral.TDeviceRatio - sourceRoot?: string - outputRoot?: string - env?: IOption - alias?: IOption - defineConstants?: IOption - copy?: ICopyOptions - jsMinimizer?: 'terser' | 'esbuild' - cssMinimizer?: 'csso' | 'esbuild' | 'parcelCss' - csso?: TogglableOptions - terser?: TogglableOptions - esbuild?: Record<'minify', TogglableOptions> - uglify?: TogglableOptions - sass?: ISassOptions - plugins?: PluginItem[] - presets?: PluginItem[] - baseLevel?: number - framework?: string - frameworkExts?: string[] - compiler?: Compiler - cache?: ICache - logger?: ILogger - enableSourceMap?: boolean - /** hooks */ - modifyWebpackChain?: HookModifyWebpackChain - modifyMiniConfigs?: (configMap) => Promise - modifyBuildAssets?: (assets, plugin?) => Promise - onWebpackChainReady?: (webpackChain: Chain) => Promise - onBuildFinish?: (res: { error, stats, isWatch }) => Promise -} - -export interface IProjectConfig extends IProjectBaseConfig { - ui?: { - extraWatchFiles?: any[] - } - mini?: IMiniAppConfig - h5?: IH5Config - rn?: IH5Config - [key: string]: any -} diff --git a/packages/taro/types/compile/compiler.d.ts b/packages/taro/types/compile/compiler.d.ts new file mode 100644 index 000000000000..600a5d632b8a --- /dev/null +++ b/packages/taro/types/compile/compiler.d.ts @@ -0,0 +1,25 @@ +import type swc from '@swc/core' +import type Webpack from 'webpack' + +type CompilerTypes = 'webpack4' | 'webpack5' + +interface IPrebundle { + enable?: boolean + timings?: boolean + cacheDir?: string + force?: boolean + include?: string[] + exclude?: string[] + esbuild?: Record + swc?: swc.Config + webpack?: Webpack.Configuration & { + provide?: any[] + } +} + +interface ICompiler { + type: CompilerTypes + prebundle: IPrebundle +} + +export type Compiler = CompilerTypes | ICompiler diff --git a/packages/taro/types/compile/config/h5.d.ts b/packages/taro/types/compile/config/h5.d.ts new file mode 100644 index 000000000000..6675734de203 --- /dev/null +++ b/packages/taro/types/compile/config/h5.d.ts @@ -0,0 +1,46 @@ +import type Webpack from 'webpack' +import type Chain from 'webpack-chain' +import type webpackDevServer from 'webpack-dev-server' +import type HtmlWebpackPlugin from 'html-webpack-plugin' +import type { IOption, IPostcssOption } from './util' + +export interface IH5RouterConfig { + mode?: 'hash' | 'browser' | 'multi' + customRoutes?: IOption + basename?: string + lazyload?: boolean | ((pagename: string) => boolean) + renamePagename?: (pagename: string) => string + forcePath?: string +} + +export interface IH5Config { + publicPath?: string + staticDirectory?: string + chunkDirectory?: string + + webpack?: ((webpackConfig: Webpack.Configuration, webpack) => Webpack.Configuration) | Webpack.Configuration + + webpackChain?: (chain: Chain, webpack: typeof Webpack) => void + + output?: Webpack.Configuration['output'] + router?: IH5RouterConfig + devServer?: webpackDevServer.Configuration + 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' + enableExtract?: boolean + transformOnly?: boolean + + cssLoaderOption?: IOption + styleLoaderOption?: IOption + sassLoaderOption?: IOption + lessLoaderOption?: IOption + stylusLoaderOption?: IOption + mediaUrlLoaderOption?: IOption + fontUrlLoaderOption?: IOption + imageUrlLoaderOption?: IOption + miniCssExtractPluginOption?: IOption + esnextModules?: string[] + useHtmlComponents?: boolean + + postcss?: IPostcssOption + htmlPluginOption?: HtmlWebpackPlugin.Options +} diff --git a/packages/taro/types/compile/config/index.d.ts b/packages/taro/types/compile/config/index.d.ts new file mode 100644 index 000000000000..97fb95fc56a9 --- /dev/null +++ b/packages/taro/types/compile/config/index.d.ts @@ -0,0 +1,6 @@ +export * from './h5' +export * from './mini' + +export * from './manifest' +export * from './project' +export * from './util' diff --git a/packages/taro/types/compile/config/manifest.d.ts b/packages/taro/types/compile/config/manifest.d.ts new file mode 100644 index 000000000000..a5c36e69e784 --- /dev/null +++ b/packages/taro/types/compile/config/manifest.d.ts @@ -0,0 +1,155 @@ +import type { IOption } from './util' + +type FeatureItem = { + name: string +} + +declare enum LogLevel { + OFF = 'off', + ERROR = 'error', + WARN = 'warn', + INFO = 'info', + LOG = 'log', + DEBUG = 'debug' +} + +export type SystemConfig = { + /** + * 打印日志等级,分为 off,error,warn,info,log,debug + */ + logLevel?: LogLevel + /** + * 页面设计基准宽度,根据实际设备宽度来缩放元素大小 + */ + designWidth?: number + /** + * 全局数据对象,属性名不能以$或_开头,在页面中可通过 this 进行访问;如果全局数据属性与页面的数据属性重名,则页面初始化时,全局数据会覆盖页面中对应的属性值 + */ + data?: IOption +} + +type RouterConfig = { + /** + * 首页名称 + */ + entry: string + /** + * 页面配置列表,key 值为页面名称(对应页面目录名,例如 Hello 对应'Hello'目录),value 为页面详细配置 page + */ + pages: RouterPage[] +} +type RouterPage = { + /** + * 页面对应的组件名,与 ux 文件名保持一致,例如'hello' 对应 'hello.ux' + */ + component: string + /** + * 页面路径,例如“/user”,不填则默认为/<页面名称>。 + * path 必须唯一,不能和其他 page 的 path 相同。 + * 下面 page 的 path 因为缺失,会被设置为“/Index”: + * "Index": {"component": "index"} + */ + path?: string + /** + * 声明页面可以处理某种请求 + */ + filter: { + [key: string]: { + uri: string + } + } +} + +interface IDefaultDisplayConfig { + /** + * 窗口背景颜色 + */ + backgroundColor?: string + /** + * 是否是全屏模式,默认不会同时作用于 titleBar,titleBar 需要继续通过 titleBar 控制 + */ + fullScreen?: boolean + /** + * 是否显示 titleBar + */ + titleBar?: boolean + /** + * 标题栏背景色 + */ + titleBarBackgroundColor?: string + /** + * 标题栏文字颜色 + */ + titleBarTextColor?: string + /** + * 标题栏文字(也可通过页面跳转传递参数(titleBarText)设置) + */ + titleBarText?: string + /** + * 是否显示标题栏右上角菜单按钮,点击菜单按钮调用页面生命周期 onMenuPress 方法,如果该方法未实现则显示系统默认菜单 + */ + menu?: boolean + /** + * 软键盘弹出时为保证输入框可见,页面的调整方式。 adjustPan:上移页面; adjustResize:压缩页面显示区域,当页面全屏时,此设置不生效 + */ + windowSoftInputMode?: 'adjustPan' | 'adjustResize' +} + +interface IDisplayConfig extends IDefaultDisplayConfig { + /** + * 各个页面的显示样式,key 为页面名(与路由中的页面名保持一致),value 为窗口显示样式,页面样式覆盖 default 样式 + */ + pages?: { + [key: string]: IDefaultDisplayConfig + } +} + +export interface ITaroManifestConfig { + /** + * 应用包名,确认与原生应用的包名不一致,推荐采用 com.company.module 的格式,如:com.example.demo + */ + package: string + /** + * 应用名称,6 个汉字以内,与应用商店保存的名称一致,用于在桌面图标、弹窗等处显示应用名称 + */ + name: string + /** + * 应用图标,提供 192x192 大小的即可 + */ + icon: string + /** + * 应用版本名称,如:"1.0" + */ + versionName?: string + /** + * 应用版本号,从1自增,推荐每次重新上传包时versionCode+1 + */ + versionCode: number + /** + * 支持的最小平台版本号,兼容性检查,避免上线后在低版本平台运行并导致不兼容;如果不填按照内测版本处理 + */ + minPlatformVersion?: string + /** + * 接口列表,绝大部分接口都需要在这里声明,否则不能调用,详见每个接口的文档说明 + */ + features?: FeatureItem[] + /** + * + */ + logLevel?: LogLevel +} + +export interface IManifestConfig extends ITaroManifestConfig { + /** + * 系统配置信息 + */ + config: SystemConfig + /** + * 路由信息 + */ + router: RouterConfig + /** + * UI 显示相关配置 + */ + display?: IDisplayConfig +} diff --git a/packages/taro/types/compile/config/mini.d.ts b/packages/taro/types/compile/config/mini.d.ts new file mode 100644 index 000000000000..0aeecd6b798a --- /dev/null +++ b/packages/taro/types/compile/config/mini.d.ts @@ -0,0 +1,48 @@ +import type Webpack from 'webpack' +import type Chain from 'webpack-chain' +import type { IMINI_APP_FILE_TYPE, IOption, IPostcssOption } from './util' + +interface Runtime { + enableInnerHTML: boolean + enableSizeAPIs: boolean + enableAdjacentHTML: boolean + enableTemplateContent: boolean + enableCloneNode: boolean + enableContains: boolean + enableMutationObserver: boolean +} + +export interface IMiniAppConfig { + appOutput?: boolean + sourceMapType?: string + debugReact?: boolean + minifyXML?: { + collapseWhitespace?: boolean + } + + webpackChain?: (chain: Chain, webpack: typeof Webpack, PARSE_AST_TYPE: any) => void + output?: Webpack.Configuration['output'] + postcss?: IPostcssOption + cssLoaderOption?: IOption + sassLoaderOption?: IOption + lessLoaderOption?: IOption + stylusLoaderOption?: IOption + mediaUrlLoaderOption?: IOption + fontUrlLoaderOption?: IOption + imageUrlLoaderOption?: IOption + miniCssExtractPluginOption?: IOption + + customFilesTypes?: IMINI_APP_FILE_TYPE + commonChunks?: string[] | ((commonChunks: string[]) => string[]) + addChunkPages?: ((pages: Map, pagesNames?: string[]) => void) + optimizeMainPackage?: { + enable?: boolean + exclude?: any[] + } + + compile?: { + exclude?: any[] + include?: any[] + } + runtime?: Runtime +} diff --git a/packages/taro/types/compile/config/project.d.ts b/packages/taro/types/compile/config/project.d.ts new file mode 100644 index 000000000000..e7afb2a78d23 --- /dev/null +++ b/packages/taro/types/compile/config/project.d.ts @@ -0,0 +1,91 @@ +import type Webpack from 'webpack' +import type Chain from 'webpack-chain' +import type { Compiler } from '../compiler' +import type { IModifyWebpackChain } from '../hooks' +import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from "./util" +import { IH5Config } from './h5' +import { IMiniAppConfig } from './mini' + +export type PluginItem = string | [string, object] + +interface ICache { + enable?: boolean + buildDependencies?: Record + name?: string +} + +interface ILogger { + quiet: boolean + stats: boolean +} + +export interface IProjectBaseConfig { + isWatch?: boolean + port?: number + projectName?: string + date?: string + designWidth?: number + watcher?: any[] + deviceRatio?: TaroGeneral.TDeviceRatio + sourceRoot?: string + outputRoot?: string + env?: IOption + alias?: IOption + defineConstants?: IOption + copy?: ICopyOptions + jsMinimizer?: 'terser' | 'esbuild' + cssMinimizer?: 'csso' | 'esbuild' | 'parcelCss' + csso?: TogglableOptions + terser?: TogglableOptions + esbuild?: Record<'minify', TogglableOptions> + uglify?: TogglableOptions + sass?: ISassOptions + plugins?: PluginItem[] + presets?: PluginItem[] + baseLevel?: number + framework?: string + frameworkExts?: string[] + compiler?: Compiler + cache?: ICache + logger?: ILogger + enableSourceMap?: boolean + /** + * 编译开始 + */ + onBuildStart?: (...args: any[]) => Promise + /** + * 编译完成(启动项目后首次编译结束后会触发一次) + */ + onBuildComplete?: (...args: any[]) => Promise + /** + * 编译结束(保存代码每次编译结束后都会触发) + */ + onBuildFinish?: (res: { error, stats, isWatch }) => Promise + /** + * 修改编译过程中的页面组件配置 + */ + onCompilerMake?: (compilation: Webpack.Compilation, compiler: Webpack.Compiler, plugin: any) => Promise + onWebpackChainReady?: (webpackChain: Chain) => Promise + /** + * 编译中修改 webpack 配置,在这个钩子中,你可以对 webpackChain 作出想要的调整,等同于配置 [`webpackChain`](./config-detail.md#miniwebpackchain) + */ + modifyWebpackChain?: (chain: Chain, webpack: typeof Webpack, data: IModifyWebpackChain) => Promise + /** + * 修改编译过程中的页面组件配置 + */ + modifyMiniConfigs?: (configMap: any) => Promise + /** + * 修改编译后的结果 + */ + modifyBuildAssets?: (assets: any, miniPlugin?: any) => Promise +} + +export interface IProjectConfig extends IProjectBaseConfig { + ui?: { + extraWatchFiles?: any[] + } + mini?: IMiniAppConfig + h5?: IH5Config + rn?: IH5Config + [key: string]: any +} diff --git a/packages/taro/types/compile/config/util.d.ts b/packages/taro/types/compile/config/util.d.ts new file mode 100644 index 000000000000..9a4f1e1408d6 --- /dev/null +++ b/packages/taro/types/compile/config/util.d.ts @@ -0,0 +1,107 @@ +export type Func = (...args: any[]) => any + +export type IOption = Record + +export type TogglableOptions = { + enable?: boolean + config?: T +} + +export namespace PostcssOption { + export type cssModules = TogglableOptions<{ + namingPattern: 'global' | string + generateScopedName: string | ((localName: string, absoluteFilePath: string) => string) + }> + export type url = TogglableOptions<{ + limit: number + basePath?: string | string[] + }> +} + +export interface IPostcssOption { + autoprefixer?: TogglableOptions + pxtransform?: TogglableOptions + cssModules?: PostcssOption.cssModules + url?: PostcssOption.url + [key: string]: any +} + +export interface ICopyOptions { + patterns: { + from: string + to: string + ignore?: string[] + transform?: Function + watch?: boolean + }[] + options: { + ignore?: string[] + } +} + +export interface ISassOptions { + /** + * 引入的全局 sass 文件,如果要引入多个文件,支持数组形式传入 + */ + resource?: string | string[] + /** + * 项目根目录的绝对地址(若为小程序云开发模板,则应该是client目录) + */ + projectDirectory?: string + /** + * 全局 scss 变量,若 data 与 resource 中设置了同样的变量,则 data 的优先级高于 resource + */ + data?: string +} + +export interface ICompileOption { + exclude?: string[] + include?: string[] +} + +export const enum TEMPLATE_TYPES { + WEAPP = '.wxml', + SWAN = '.swan', + ALIPAY = '.axml', + TT = '.ttml', + QUICKAPP = '.ux', + QQ = '.qml' +} + +export const enum STYLE_TYPES { + WEAPP = '.wxss', + SWAN = '.css', + ALIPAY = '.acss', + TT = '.ttss', + QUICKAPP = '.css', + QQ = '.qss' +} + +export const enum SCRIPT_TYPES { + WEAPP = '.js', + SWAN = '.js', + ALIPAY = '.js', + TT = '.js', + QUICKAPP = '.js', + QQ = '.js' +} + +export const enum CONFIG_TYPES { + WEAPP = '.json', + SWAN = '.json', + ALIPAY = '.json', + TT = '.json', + QUICKAPP = '.json', + QQ = '.json' +} + +export type IMINI_APP_FILE_TYPE = { + TEMPL: TEMPLATE_TYPES, + STYLE: STYLE_TYPES, + SCRIPT: SCRIPT_TYPES, + CONFIG: CONFIG_TYPES +} + +export type IMINI_APP_FILES = { + [key: string]: IMINI_APP_FILE_TYPE +} diff --git a/packages/taro/types/compile/hooks.d.ts b/packages/taro/types/compile/hooks.d.ts new file mode 100644 index 000000000000..efb9bca2a0bb --- /dev/null +++ b/packages/taro/types/compile/hooks.d.ts @@ -0,0 +1,13 @@ +type Tagname = string +type Attrs = Set + +interface IComponentConfig { + includes: Set + exclude: Set + thirdPartyComponents: Map + includeAll: boolean +} + +export interface IModifyWebpackChain { + componentConfig?: IComponentConfig +} diff --git a/packages/taro/types/compile/index.d.ts b/packages/taro/types/compile/index.d.ts new file mode 100644 index 000000000000..8d887a2d88bc --- /dev/null +++ b/packages/taro/types/compile/index.d.ts @@ -0,0 +1,3 @@ +export { Current } from '@tarojs/runtime' + +export * from './config' diff --git a/packages/taro/types/taro.component.d.ts b/packages/taro/types/taro.component.d.ts index aeb4fb033558..636ed63eddfc 100644 --- a/packages/taro/types/taro.component.d.ts +++ b/packages/taro/types/taro.component.d.ts @@ -28,7 +28,7 @@ declare module './index' { onHide?(): void } interface AppInstance extends Show { - mount(component: React.Component | Vue.ComponentOptions, id: string, cb: (...args: any[]) => void): void + mount(component: React.Component | Vue.ComponentOptions, id: string, cb: (...args: any[]) => void): void componentDidShow?(options?: Record): void onShow?(options?: Record): void unmount(id: string, cb?: () => void): void