From 2dd144b08a1cbdc7be9252d9259facb5015d4978 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 22 Mar 2023 11:39:54 +0800 Subject: [PATCH] fix(h5): ssr --- packages/uni-cli-shared/src/hbx/alias.ts | 1 + packages/uni-h5-vite/src/utils/ssr.ts | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/uni-cli-shared/src/hbx/alias.ts b/packages/uni-cli-shared/src/hbx/alias.ts index aa3ed6165c..3b67146c0b 100644 --- a/packages/uni-cli-shared/src/hbx/alias.ts +++ b/packages/uni-cli-shared/src/hbx/alias.ts @@ -29,6 +29,7 @@ export function initModuleAlias() { if (process.env.VITEST) { moduleAlias.addAliases({ vue: '@dcloudio/uni-h5-vue', + 'vue/package.json': '@dcloudio/uni-h5-vue/package.json', }) } if (isInHBuilderX()) { diff --git a/packages/uni-h5-vite/src/utils/ssr.ts b/packages/uni-h5-vite/src/utils/ssr.ts index 6d769130c4..3d65c7d17b 100644 --- a/packages/uni-h5-vite/src/utils/ssr.ts +++ b/packages/uni-h5-vite/src/utils/ssr.ts @@ -81,10 +81,10 @@ export function generateSsrEntryServerCode() { export function rewriteSsrVue() { // 解决 @vue/server-renderer 中引入 vue 的映射 - require('module-alias').addAlias( - 'vue', - resolveBuiltIn('@dcloudio/uni-h5-vue/dist/vue.runtime.cjs.js') - ) + require('module-alias').addAliases({ + vue: resolveBuiltIn('@dcloudio/uni-h5-vue/dist/vue.runtime.cjs.js'), + 'vue/package.json': resolveBuiltIn('@dcloudio/uni-h5-vue/package.json'), + }) // TODO vite 2.7.0 版本会定制 require 的解析,解析后缓存的文件路径会被格式化,导致 windows 平台路径不一致,导致 cache 不生效 if (require('os').platform() === 'win32') { require('vue') -- GitLab