From 1f3d02d28e222998cea94ddf0c5e43df532949ba Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Mon, 22 Jan 2024 19:37:55 +0800 Subject: [PATCH 01/12] fix(h5): custom proxy connect --- packages/taro-webpack-runner/src/index.ts | 2 ++ packages/taro-webpack5-runner/src/index.h5.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/taro-webpack-runner/src/index.ts b/packages/taro-webpack-runner/src/index.ts index a09a996519..76bc1c7468 100644 --- a/packages/taro-webpack-runner/src/index.ts +++ b/packages/taro-webpack-runner/src/index.ts @@ -150,6 +150,8 @@ const buildDev = async (appPath: string, config: BuildConfig, appHelper: AppHelp } return item })) + } else { + proxy.push(...customProxy) } if (typeof config.onWebpackChainReady === 'function') { diff --git a/packages/taro-webpack5-runner/src/index.h5.ts b/packages/taro-webpack5-runner/src/index.h5.ts index 5655a124c9..117db038f6 100644 --- a/packages/taro-webpack5-runner/src/index.h5.ts +++ b/packages/taro-webpack5-runner/src/index.h5.ts @@ -226,6 +226,8 @@ async function getDevServerOptions (appPath: string, config: H5BuildConfig): Pro } return item })) + } else { + proxy.push(...customProxy) } const chunkFilename = config.output?.chunkFilename as string ?? `${config.chunkDirectory || 'chunk'}/[name].js` From 39bdb784b59e94a529d115c7f613f1abc6b002dd Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Mon, 22 Jan 2024 16:03:08 +0800 Subject: [PATCH 02/12] =?UTF-8?q?fix(h5):=20=E6=94=BE=E5=BC=80=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=A8=A1=E5=BC=8F=20dev-server=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BE=9B=E5=BC=80=E5=8F=91=E8=80=85=E8=87=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-webpack-runner/src/index.ts | 33 ++++++++++--------- packages/taro-webpack5-runner/src/index.h5.ts | 10 ++---- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/packages/taro-webpack-runner/src/index.ts b/packages/taro-webpack-runner/src/index.ts index 76bc1c7468..3d2ff9bdb8 100644 --- a/packages/taro-webpack-runner/src/index.ts +++ b/packages/taro-webpack-runner/src/index.ts @@ -158,23 +158,24 @@ const buildDev = async (appPath: string, config: BuildConfig, appHelper: AppHelp config.onWebpackChainReady(webpackChain) } - const devServerOptions = config.isBuildNativeComp - ? { writeToDisk: true } - : recursiveMerge( - { - publicPath, - contentBase: outputPath, - historyApiFallback: { - rewrites: [{ - from: /./, - to: publicPath - }] - }, - proxy, + const devServerOptions = recursiveMerge( + { + open: !config.isBuildNativeComp, + publicPath, + contentBase: outputPath, + writeToDisk: config.isBuildNativeComp, + historyApiFallback: { + rewrites: [{ + from: /./, + to: publicPath + }] }, - baseDevServerOption, - customDevServerOption - ) + proxy, + }, + baseDevServerOption, + customDevServerOption + ) + if (devServerOptions.proxy?.length < 1) { // Note: proxy 不可以为空数组 delete devServerOptions.proxy diff --git a/packages/taro-webpack5-runner/src/index.h5.ts b/packages/taro-webpack5-runner/src/index.h5.ts index 117db038f6..75420c9ffd 100644 --- a/packages/taro-webpack5-runner/src/index.h5.ts +++ b/packages/taro-webpack5-runner/src/index.h5.ts @@ -148,13 +148,6 @@ export default async function build (appPath: string, rawConfig: H5BuildConfig): } async function getDevServerOptions (appPath: string, config: H5BuildConfig): Promise { - if (config.isBuildNativeComp) { - return { - devMiddleware: { - writeToDisk: true - } - } - } const publicPath = parsePublicPath(config.publicPath) const outputPath = path.join(appPath, config.outputRoot || 'dist') const { proxy: customProxy = [], ...customDevServerOption } = config.devServer || {} @@ -233,9 +226,10 @@ async function getDevServerOptions (appPath: string, config: H5BuildConfig): Pro const chunkFilename = config.output?.chunkFilename as string ?? `${config.chunkDirectory || 'chunk'}/[name].js` const devServerOptions: WebpackDevServer.Configuration = recursiveMerge( { + open: !config.isBuildNativeComp, devMiddleware: { publicPath, - writeToDisk: false + writeToDisk: config.isBuildNativeComp }, static: [{ directory: outputPath, // webpack4: devServerOptions.contentBase From 6218df9f020341a235e48db6843b12b5abe39784 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Wed, 24 Jan 2024 18:51:47 +0800 Subject: [PATCH 03/12] feat(h5): dev default allowedHosts all --- packages/taro-webpack-runner/src/index.ts | 1 + packages/taro-webpack5-runner/src/index.h5.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/taro-webpack-runner/src/index.ts b/packages/taro-webpack-runner/src/index.ts index 3d2ff9bdb8..aaa6f5c690 100644 --- a/packages/taro-webpack-runner/src/index.ts +++ b/packages/taro-webpack-runner/src/index.ts @@ -161,6 +161,7 @@ const buildDev = async (appPath: string, config: BuildConfig, appHelper: AppHelp const devServerOptions = recursiveMerge( { open: !config.isBuildNativeComp, + disableHostCheck: true, publicPath, contentBase: outputPath, writeToDisk: config.isBuildNativeComp, diff --git a/packages/taro-webpack5-runner/src/index.h5.ts b/packages/taro-webpack5-runner/src/index.h5.ts index 75420c9ffd..6dc55f1d9b 100644 --- a/packages/taro-webpack5-runner/src/index.h5.ts +++ b/packages/taro-webpack5-runner/src/index.h5.ts @@ -227,6 +227,7 @@ async function getDevServerOptions (appPath: string, config: H5BuildConfig): Pro const devServerOptions: WebpackDevServer.Configuration = recursiveMerge( { open: !config.isBuildNativeComp, + allowedHosts: 'all', devMiddleware: { publicPath, writeToDisk: config.isBuildNativeComp From 51ccc64391a26576a23ba6027d80f339f1063143 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Sat, 20 Jan 2024 00:10:15 +0000 Subject: [PATCH 04/12] refactor(types): sync components types --- .../taro/types/api/{open-api => swan}/bookshelf.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename packages/taro/types/api/{open-api => swan}/bookshelf.d.ts (99%) diff --git a/packages/taro/types/api/open-api/bookshelf.d.ts b/packages/taro/types/api/swan/bookshelf.d.ts similarity index 99% rename from packages/taro/types/api/open-api/bookshelf.d.ts rename to packages/taro/types/api/swan/bookshelf.d.ts index 258ede2e6c..ae3e6343f5 100644 --- a/packages/taro/types/api/open-api/bookshelf.d.ts +++ b/packages/taro/types/api/swan/bookshelf.d.ts @@ -43,7 +43,7 @@ declare module '../../index' { 1 } } - + namespace deleteBookshelf { interface Option { /** 要删除的内容分类 */ @@ -115,13 +115,13 @@ declare module '../../index' { 1 } } - + namespace updateBookshelfReadTime { interface Option { /** 添加的内容分类 */ category: keyof Category | string /** 要更新内容的 id;注释:contentId 为内容 id,内容的唯一标识,自定义,最长 22 字符(不能含有空格、中文字符) */ - contentIds: string[] + contentIds: string[] /** 接口调用结束的回调函数(调用成功、失败都会执行) */ complete?: (res: TaroGeneral.CallbackResult) => void /** 接口调用失败的回调函数 */ @@ -278,7 +278,7 @@ declare module '../../index' { * @see https://smartprogram.baidu.com/docs/develop/api/open/swan-queryBookshelf/ */ updateBookshelfReadTime(option: updateBookshelfReadTime.Option): void - + /** 跳转到宿主书架 * @supported swan * @swan (需宿主支持书架入口) @@ -304,4 +304,4 @@ declare module '../../index' { */ navigateToBookshelf(option: navigateToBookshelf.Option): void } -} \ No newline at end of file +} From 3d857b130c2167e76c03868f770b7a17ad237769 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Mon, 22 Jan 2024 11:26:10 +0800 Subject: [PATCH 05/12] feat(runner): support no build --- packages/taro-cli/src/cli.ts | 11 ++++++++--- packages/taro-cli/src/presets/commands/build.ts | 7 +++++-- packages/taro-mini-runner/src/index.ts | 2 ++ packages/taro-mini-runner/src/utils/types.ts | 1 + packages/taro-webpack-runner/src/index.ts | 4 ++++ packages/taro-webpack-runner/src/utils/types.ts | 1 + packages/taro-webpack5-runner/src/index.h5.ts | 4 ++++ packages/taro-webpack5-runner/src/index.mini.ts | 6 ++++-- packages/taro-webpack5-runner/src/utils/types.ts | 1 + 9 files changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/taro-cli/src/cli.ts b/packages/taro-cli/src/cli.ts index 09236774ad..b672ab3827 100644 --- a/packages/taro-cli/src/cli.ts +++ b/packages/taro-cli/src/cli.ts @@ -33,7 +33,10 @@ export default class CLI { assetsDest: ['assets-dest'], // specially for rn, Directory name where to store assets referenced in the bundle. envPrefix: ['env-prefix'], }, - boolean: ['version', 'help', 'disable-global-config'] + boolean: ['version', 'help', 'disable-global-config'], + default: { + build: true, + }, }) const _ = args._ const command = _[0] @@ -166,10 +169,12 @@ export default class CLI { platform, plugin, isWatch: Boolean(args.watch), - // 是否把 Taro 组件编译为原生自定义组件 + // Note: 是否把 Taro 组件编译为原生自定义组件 isBuildNativeComp: _[1] === 'native-components', - // 新的混合编译模式,支持把组件单独编译为原生组件 + // Note: 新的混合编译模式,支持把组件单独编译为原生组件 newBlended: Boolean(args['new-blended']), + // Note: 是否禁用编译 + withoutBuild: !args.build, port: args.port, env: args.env, deviceType: args.platform, diff --git a/packages/taro-cli/src/presets/commands/build.ts b/packages/taro-cli/src/presets/commands/build.ts index f8dbf65565..37c0430a88 100644 --- a/packages/taro-cli/src/presets/commands/build.ts +++ b/packages/taro-cli/src/presets/commands/build.ts @@ -16,6 +16,7 @@ export default (ctx: IPluginContext) => { '--env [env]': 'Value for process.env.NODE_ENV', '--mode [mode]': 'Value of dotenv extname', '-p, --port [port]': 'Specified port', + '--no-build': 'Do not build project', '--platform': '[rn] Specific React-Native build target: android / ios, android is default value', '--reset-cache': '[rn] Clear transform cache', '--public-path': '[rn] Assets public path', @@ -35,15 +36,16 @@ export default (ctx: IPluginContext) => { 'taro build --type weapp --watch', 'taro build --type weapp --env production', 'taro build --type weapp --blended', + 'taro build --type weapp --no-build', 'taro build native-components --type weapp', 'taro build --type weapp --new-blended', 'taro build --plugin weapp --watch', 'taro build --plugin weapp', - 'taro build --type weapp --mode prepare --env-prefix TARO_APP_' + 'taro build --type weapp --mode prepare --env-prefix TARO_APP_', ], async fn (opts) { const { options, config, _ } = opts - const { platform, isWatch, blended, newBlended } = options + const { platform, isWatch, blended, newBlended, withoutBuild } = options const { fs, chalk, PROJECT_CONFIG } = ctx.helper const { outputPath, configPath } = ctx.paths @@ -110,6 +112,7 @@ export default (ctx: IPluginContext) => { mode: isProduction ? 'production' : 'development', blended, isBuildNativeComp, + withoutBuild, newBlended, async modifyWebpackChain (chain, webpack, data) { await ctx.applyPlugins({ diff --git a/packages/taro-mini-runner/src/index.ts b/packages/taro-mini-runner/src/index.ts index 6835646c9a..6d9ea72f48 100644 --- a/packages/taro-mini-runner/src/index.ts +++ b/packages/taro-mini-runner/src/index.ts @@ -52,6 +52,8 @@ export default async function build (appPath: string, config: IBuildConfig): Pro const webpackConfig: webpack.Configuration = webpackChain.toConfig() return new Promise((resolve, reject) => { + if (config.withoutBuild) return + const compiler = webpack(webpackConfig) const onBuildFinish = newConfig.onBuildFinish let prerender: Prerender diff --git a/packages/taro-mini-runner/src/utils/types.ts b/packages/taro-mini-runner/src/utils/types.ts index d3f1b395eb..ef8c89b2d8 100644 --- a/packages/taro-mini-runner/src/utils/types.ts +++ b/packages/taro-mini-runner/src/utils/types.ts @@ -48,6 +48,7 @@ export interface IBuildConfig extends IProjectBaseConfig, IMiniAppConfig { isBuildQuickapp: boolean isSupportRecursive: boolean isSupportXS: boolean + withoutBuild?: boolean mode: 'production' | 'development' modifyComponentConfig: Func nodeModulesPath: string diff --git a/packages/taro-webpack-runner/src/index.ts b/packages/taro-webpack-runner/src/index.ts index aaa6f5c690..329f47094c 100644 --- a/packages/taro-webpack-runner/src/index.ts +++ b/packages/taro-webpack-runner/src/index.ts @@ -45,6 +45,8 @@ const buildProd = async (appPath: string, config: BuildConfig, appHelper: AppHel } const errorLevel = typeof config.compiler !== 'string' && config.compiler?.errorLevel || 0 const webpackConfig = webpackChain.toConfig() + if (config.withoutBuild) return + const compiler = webpack(webpackConfig) const onBuildFinish = config.onBuildFinish compiler.hooks.emit.tapAsync('taroBuildDone', async (compilation, callback) => { @@ -214,6 +216,8 @@ const buildDev = async (appPath: string, config: BuildConfig, appHelper: AppHelp const webpackConfig = webpackChain.toConfig() WebpackDevServer.addDevServerEntrypoints(webpackConfig, devServerOptions) + if (config.withoutBuild) return + const compiler = webpack(webpackConfig) as webpack.Compiler bindDevLogger(compiler, devUrl) const server = new WebpackDevServer(compiler, devServerOptions) diff --git a/packages/taro-webpack-runner/src/utils/types.ts b/packages/taro-webpack-runner/src/utils/types.ts index dff2152314..7e4d454c37 100644 --- a/packages/taro-webpack-runner/src/utils/types.ts +++ b/packages/taro-webpack-runner/src/utils/types.ts @@ -19,6 +19,7 @@ export interface BuildConfig extends IProjectBaseConfig, IH5Config { runtimePath?: string | string[] /** special mode */ isBuildNativeComp?: boolean + withoutBuild?: boolean /** hooks */ onCompilerMake: (compilation) => Promise onParseCreateElement: (nodeName, componentConfig) => Promise diff --git a/packages/taro-webpack5-runner/src/index.h5.ts b/packages/taro-webpack5-runner/src/index.h5.ts index 6dc55f1d9b..2e1d6779f8 100644 --- a/packages/taro-webpack5-runner/src/index.h5.ts +++ b/packages/taro-webpack5-runner/src/index.h5.ts @@ -51,6 +51,8 @@ export default async function build (appPath: string, rawConfig: H5BuildConfig): try { if (!config.isWatch) { + if (config.withoutBuild) return + const compiler = webpack(webpackConfig) prebundle?.postCompilerStart(compiler) compiler.hooks.emit.tapAsync('taroBuildDone', async (compilation, callback) => { @@ -98,6 +100,8 @@ export default async function build (appPath: string, rawConfig: H5BuildConfig): webpackConfig.devServer.open = devUrl } + if (config.withoutBuild) return + const compiler = webpack(webpackConfig) const server = new WebpackDevServer(webpackConfig.devServer, compiler) prebundle?.postCompilerStart(compiler) diff --git a/packages/taro-webpack5-runner/src/index.mini.ts b/packages/taro-webpack5-runner/src/index.mini.ts index 9f24653ae6..ce5eded199 100644 --- a/packages/taro-webpack5-runner/src/index.mini.ts +++ b/packages/taro-webpack5-runner/src/index.mini.ts @@ -10,7 +10,7 @@ import { MiniCombination } from './webpack/MiniCombination' import type { Stats } from 'webpack' import type { MiniBuildConfig } from './utils/types' -export default async function build (appPath: string, rawConfig: MiniBuildConfig): Promise { +export default async function build (appPath: string, rawConfig: MiniBuildConfig): Promise { const combination = new MiniCombination(appPath, rawConfig) await combination.make() @@ -37,7 +37,9 @@ export default async function build (appPath: string, rawConfig: MiniBuildConfig const webpackConfig = combination.chain.toConfig() const config = combination.config - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { + if (config.withoutBuild) return + const compiler = webpack(webpackConfig) const onBuildFinish = config.onBuildFinish let prerender: Prerender diff --git a/packages/taro-webpack5-runner/src/utils/types.ts b/packages/taro-webpack5-runner/src/utils/types.ts index 32201ffd01..4f1140e6f6 100644 --- a/packages/taro-webpack5-runner/src/utils/types.ts +++ b/packages/taro-webpack5-runner/src/utils/types.ts @@ -42,6 +42,7 @@ export interface CommonBuildConfig extends IProjectBaseConfig { /** special mode */ isBuildNativeComp?: boolean newBlended?: boolean + withoutBuild?: boolean /** hooks */ onCompilerMake: (compilation: Webpack.Compilation, compiler: Webpack.Compiler, plugin: any) => Promise onParseCreateElement: (nodeName, componentConfig) => Promise From c4e2673498bc3c8300e8611a79d65db08c7f2a59 Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Mon, 22 Jan 2024 11:26:59 +0800 Subject: [PATCH 06/12] fix(h5): support modifyComponentConfig --- packages/taro-webpack-runner/src/config/dev.conf.ts | 4 ++++ packages/taro-webpack-runner/src/config/prod.conf.ts | 4 ++++ packages/taro-webpack-runner/src/plugins/H5Plugin.ts | 5 ++++- packages/taro-webpack-runner/src/utils/types.ts | 4 +++- packages/taro-webpack5-runner/src/plugins/H5Plugin.ts | 5 ++++- packages/taro-webpack5-runner/src/utils/types.ts | 3 +-- packages/taro-webpack5-runner/src/webpack/H5Combination.ts | 7 ++++++- 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/taro-webpack-runner/src/config/dev.conf.ts b/packages/taro-webpack-runner/src/config/dev.conf.ts index 9d325afa93..fc4708dc49 100644 --- a/packages/taro-webpack-runner/src/config/dev.conf.ts +++ b/packages/taro-webpack-runner/src/config/dev.conf.ts @@ -15,6 +15,7 @@ import { parseModule, processEnvOption } from '../utils/chain' +import { componentConfig } from '../utils/component' import getBaseChain from './base.conf' import type { BuildConfig } from '../utils/types' @@ -167,6 +168,9 @@ export default function (appPath: string, config: Partial, appHelpe publicPath: ['', 'auto'].includes(publicPath) ? publicPath : addTrailingSlash(publicPath), chunkDirectory }, output]) + + config.modifyComponentConfig?.(componentConfig, config) + if (config.isBuildNativeComp) { // Note: 当开发者没有配置时,优先使用 module 导出组件 webpackOutput.libraryTarget ||= 'commonjs' diff --git a/packages/taro-webpack-runner/src/config/prod.conf.ts b/packages/taro-webpack-runner/src/config/prod.conf.ts index e50473c39f..ac9b524aac 100644 --- a/packages/taro-webpack-runner/src/config/prod.conf.ts +++ b/packages/taro-webpack-runner/src/config/prod.conf.ts @@ -17,6 +17,7 @@ import { parseModule, processEnvOption } from '../utils/chain' +import { componentConfig } from '../utils/component' import getBaseChain from './base.conf' import type { BuildConfig } from '../utils/types' @@ -190,6 +191,9 @@ export default function (appPath: string, config: Partial, appHelpe publicPath: ['', 'auto'].includes(publicPath) ? publicPath : addTrailingSlash(publicPath), chunkDirectory }, output]) + + config.modifyComponentConfig?.(componentConfig, config) + if (config.isBuildNativeComp) { // Note: 当开发者没有配置时,优先使用 module 导出组件 webpackOutput.libraryTarget ||= 'commonjs' diff --git a/packages/taro-webpack-runner/src/plugins/H5Plugin.ts b/packages/taro-webpack-runner/src/plugins/H5Plugin.ts index dc61428ffa..a144befe4c 100644 --- a/packages/taro-webpack-runner/src/plugins/H5Plugin.ts +++ b/packages/taro-webpack-runner/src/plugins/H5Plugin.ts @@ -6,6 +6,7 @@ import { defaults } from 'lodash' import * as path from 'path' import { AppHelper } from '../utils' +import { componentConfig } from '../utils/component' import TaroComponentsExportsPlugin from './TaroComponentsExportsPlugin' import type { Func } from '@tarojs/taro/types/compile' @@ -131,7 +132,9 @@ export default class TaroH5Plugin { }) }) - new TaroComponentsExportsPlugin(this.options).apply(compiler) + if (!componentConfig.includeAll) { + new TaroComponentsExportsPlugin(this.options).apply(compiler) + } } run () { diff --git a/packages/taro-webpack-runner/src/utils/types.ts b/packages/taro-webpack-runner/src/utils/types.ts index 7e4d454c37..16e926f619 100644 --- a/packages/taro-webpack-runner/src/utils/types.ts +++ b/packages/taro-webpack-runner/src/utils/types.ts @@ -1,6 +1,7 @@ -import { IH5Config, IProjectBaseConfig } from '@tarojs/taro/types/compile' import * as webpack from 'webpack' +import type { Func, IH5Config, IProjectBaseConfig } from '@tarojs/taro/types/compile' + type FunctionLikeCustomWebpackConfig = (webpackConfig: webpack.Configuration, webpack) => webpack.Configuration export type CustomWebpackConfig = FunctionLikeCustomWebpackConfig | webpack.Configuration @@ -23,4 +24,5 @@ export interface BuildConfig extends IProjectBaseConfig, IH5Config { /** hooks */ onCompilerMake: (compilation) => Promise onParseCreateElement: (nodeName, componentConfig) => Promise + modifyComponentConfig: Func } diff --git a/packages/taro-webpack5-runner/src/plugins/H5Plugin.ts b/packages/taro-webpack5-runner/src/plugins/H5Plugin.ts index 6cf2a25b71..0d1e64aa84 100644 --- a/packages/taro-webpack5-runner/src/plugins/H5Plugin.ts +++ b/packages/taro-webpack5-runner/src/plugins/H5Plugin.ts @@ -3,6 +3,7 @@ import { defaults } from 'lodash' import path from 'path' import AppHelper from '../utils/app' +import { componentConfig } from '../utils/component' import TaroComponentsExportsPlugin from './TaroComponentsExportsPlugin' import type { Func } from '@tarojs/taro/types/compile' @@ -149,7 +150,9 @@ export default class TaroH5Plugin { }) }) - new TaroComponentsExportsPlugin(this.options).apply(compiler) + if (!componentConfig.includeAll) { + new TaroComponentsExportsPlugin(this.options).apply(compiler) + } } run () { diff --git a/packages/taro-webpack5-runner/src/utils/types.ts b/packages/taro-webpack5-runner/src/utils/types.ts index 4f1140e6f6..00f86b79f8 100644 --- a/packages/taro-webpack5-runner/src/utils/types.ts +++ b/packages/taro-webpack5-runner/src/utils/types.ts @@ -46,6 +46,7 @@ export interface CommonBuildConfig extends IProjectBaseConfig { /** hooks */ onCompilerMake: (compilation: Webpack.Compilation, compiler: Webpack.Compiler, plugin: any) => Promise onParseCreateElement: (nodeName, componentConfig) => Promise + modifyComponentConfig: (componentConfig: IComponentConfig, config: Partial) => Promise } export interface MiniBuildConfig extends CommonBuildConfig, IMiniAppConfig { @@ -62,8 +63,6 @@ export interface MiniBuildConfig extends CommonBuildConfig, IMiniAppConfig { taroComponentsPath?: string blended?: boolean hot?: boolean - /** hooks */ - modifyComponentConfig: (componentConfig: IComponentConfig, config: Partial) => Promise } export interface H5BuildConfig extends CommonBuildConfig, IH5Config { diff --git a/packages/taro-webpack5-runner/src/webpack/H5Combination.ts b/packages/taro-webpack5-runner/src/webpack/H5Combination.ts index 10f36ac577..49c884b382 100644 --- a/packages/taro-webpack5-runner/src/webpack/H5Combination.ts +++ b/packages/taro-webpack5-runner/src/webpack/H5Combination.ts @@ -1,5 +1,6 @@ import { parsePublicPath } from '../utils' import AppHelper from '../utils/app' +import { componentConfig } from '../utils/component' import { Combination } from './Combination' import { H5BaseConfig } from './H5BaseConfig' import { H5WebpackModule } from './H5WebpackModule' @@ -33,7 +34,9 @@ export class H5Combination extends Combination { alias = {}, defineConstants = {}, router, - frameworkExts + frameworkExts, + /** hooks */ + modifyComponentConfig, } = config const externals: Configuration['externals'] = [] const routerMode = router?.mode || 'hash' @@ -46,6 +49,8 @@ export class H5Combination extends Combination { defineConstants, }) + modifyComponentConfig?.(componentConfig, config) + if (this.isBuildNativeComp) { delete entry[entryFileName] this.appHelper.compsConfigList.forEach((comp, index) => { From 8b3249d28912b99e152dc087a59af8c8eb90528d Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Mon, 22 Jan 2024 15:25:09 +0800 Subject: [PATCH 07/12] test: update cli have been called --- packages/taro-cli/src/__tests__/cli.spec.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/taro-cli/src/__tests__/cli.spec.ts b/packages/taro-cli/src/__tests__/cli.spec.ts index 655edef31a..74e2404df7 100644 --- a/packages/taro-cli/src/__tests__/cli.spec.ts +++ b/packages/taro-cli/src/__tests__/cli.spec.ts @@ -42,6 +42,7 @@ describe('inspect', () => { platform: undefined, publicPath: undefined, isWatch: false, + withoutBuild: false, env: undefined, blended: false, assetsDest: undefined, @@ -168,7 +169,9 @@ describe('inspect', () => { name: 'convert', opts: { _: ['convert'], - options: {}, + options: { + build: true, + }, isHelp: false } }) @@ -188,6 +191,7 @@ describe('inspect', () => { opts: { _, options: { + build: true, type }, isHelp: true From 71a1bc4cd1e7d1810fe4eb2d6e13aa3a1b8e680d Mon Sep 17 00:00:00 2001 From: ZakaryCode Date: Tue, 23 Jan 2024 18:29:08 +0800 Subject: [PATCH 08/12] =?UTF-8?q?feat(server):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=AB=AF=E8=87=AA=E5=AE=9A=E4=B9=89=E9=85=8D=E7=BD=AE=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-service/src/Config.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/taro-service/src/Config.ts b/packages/taro-service/src/Config.ts index b5aa7d12d5..8f40d37318 100644 --- a/packages/taro-service/src/Config.ts +++ b/packages/taro-service/src/Config.ts @@ -119,7 +119,8 @@ export default class Config { cssMinimizer: initialConfig.cssMinimizer, terser: initialConfig.terser, esbuild: initialConfig.esbuild, - ...initialConfig[configName] + ...initialConfig[configName], + ...initialConfig[platform], } } } From e789db0f9916cc2eab9ecbfd2564b83fc948c42a Mon Sep 17 00:00:00 2001 From: heweishui Date: Fri, 26 Jan 2024 17:38:54 +0800 Subject: [PATCH 09/12] =?UTF-8?q?feat:=20chooseLocation=E6=8E=A5=E5=8F=A3h?= =?UTF-8?q?armony=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api/apis/comments.ts | 8 - .../src/api/apis/location/chooseLocation.ts | 192 ++++++++++++++++++ .../src/api/apis/location/index.ts | 3 +- 3 files changed, 194 insertions(+), 9 deletions(-) create mode 100644 packages/taro-platform-harmony-hybrid/src/api/apis/location/chooseLocation.ts diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/comments.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/comments.ts index becc77eefa..45380bea18 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/comments.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/comments.ts @@ -55,14 +55,6 @@ * @canNotUse checkIsSupportSoterAuthentication */ -/** - * 打开地图选择位置。 - * - * @canUse chooseLocation - * @__object [mapOpts] - * @__success [address, latitude, longitude, name] - */ - /** * 拍摄视频或从手机相册中选视频 * diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/chooseLocation.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/chooseLocation.ts new file mode 100644 index 0000000000..3a77f11ff4 --- /dev/null +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/chooseLocation.ts @@ -0,0 +1,192 @@ +import Taro from '@tarojs/api' +import { stringify } from 'query-string' + +import { MethodHandler } from '../utils/handler' + +let container: HTMLDivElement | null = null +function createLocationChooser (handler, mapOpt: Taro.chooseLocation.Option['mapOpts'] = {}) { + // @ts-ignore + const systemBarHeight = window.systemBarHeight ? window.systemBarHeight : 0 + const { key = LOCATION_APIKEY, referer = 'myapp', ...opts } = mapOpt + const query = { + key, + type: 1, + referer, + ...opts, + } + if (!container) { + const css = ` +.taro_choose_location { + display: flex; + position: fixed; + top: 100%; + z-index: 1; + flex-direction: column; + width: 100%; + height: 100%; + background-color: #fff; + transition: ease top 0.3s; +} +.taro_choose_location_bar { + display: flex; + flex: 0 60px; + height: 60px; + background-color: #ededed; + color: #090909; + align-items: center; +} +.taro_choose_location_back { + position: relative; + flex: 0 40px; + margin-left: 10px; + width: 25px; + height: 30px; +} +.taro_choose_location_back::before { + display: block; + position: absolute; + left: 0; + top: 0; + border: solid 15px; + border-color: transparent #090909 transparent transparent; + width: 0; + height: 0; + content: ""; +} +.taro_choose_location_back::after { + display: block; + position: absolute; + left: 3px; + top: 0; + border: solid 15px; + border-color: transparent #ededed transparent transparent; + width: 0; + height: 0; + content: ""; +} +.taro_choose_location_title { + flex: 1; + padding-left: 30px; + line-height: 60px; +} +.taro_choose_location_submit { + margin-right: 25px; + padding: 0; + border: none; + width: 75px; + height: 40px; + background-color: #08bf62; + line-height: 40px; + font-size: 20px; + color: #fff; +} +.taro_choose_location_frame { + flex: 1; +} +` + const style = document.createElement('style') + style.innerHTML = css + document.getElementsByTagName('head')[0].appendChild(style) + + const html = ` +
+
+
+
+

位置

+ +
+