From 489208e4e4a44b2edf334025af8aa85b5ada1ca8 Mon Sep 17 00:00:00 2001 From: BluesCurry <18832643723@163.com> Date: Thu, 14 Mar 2024 13:55:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE=20d?= =?UTF-8?q?evServer=20=E7=9A=84=20historyApiFallback=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98=20(#15310)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复设置 devServer 的 historyApiFallback 配置不生效问题 * feat: 同步 webpack5 改动 --------- Co-authored-by: ZEJIA LIU <53506531+ZEJIA-LIU@users.noreply.github.com> Co-authored-by: liuzejia --- packages/taro-webpack-runner/src/index.ts | 12 +++++++----- packages/taro-webpack5-runner/src/index.h5.ts | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/taro-webpack-runner/src/index.ts b/packages/taro-webpack-runner/src/index.ts index 329f47094cd9..8d1cbd0303d0 100644 --- a/packages/taro-webpack-runner/src/index.ts +++ b/packages/taro-webpack-runner/src/index.ts @@ -167,16 +167,18 @@ const buildDev = async (appPath: string, config: BuildConfig, appHelper: AppHelp publicPath, contentBase: outputPath, writeToDisk: config.isBuildNativeComp, + proxy, + }, + baseDevServerOption, + customDevServerOption, + { historyApiFallback: { rewrites: [{ from: /./, to: publicPath }] - }, - proxy, - }, - baseDevServerOption, - customDevServerOption + } + } ) if (devServerOptions.proxy?.length < 1) { diff --git a/packages/taro-webpack5-runner/src/index.h5.ts b/packages/taro-webpack5-runner/src/index.h5.ts index 0d4f90275b70..62f394291fa9 100644 --- a/packages/taro-webpack5-runner/src/index.h5.ts +++ b/packages/taro-webpack5-runner/src/index.h5.ts @@ -261,14 +261,16 @@ async function getDevServerOptions (appPath: string, config: H5BuildConfig): Pro const pathname = chunkFilename.replace('[name]', path.basename(context.parsedUrl.pathname).replace(/\.[^.]*.hot-update\.(js|json)/, '')) return (['', 'auto'].includes(publicPath) ? '' : publicPath) + pathname } - }, { - from: /./, - to: publicPath }] }, proxy }, - customDevServerOption + customDevServerOption, + { + historyApiFallback: { + rewrites: [{ from: /./, to: publicPath }] + } + } ) const originalPort = Number(devServerOptions.port)