Skip to content

Commit 64ec27b

Browse files
fix(ssr): normalize manifest filenames (#3706)
* fix(ssr): normalize manifest filenames Fixes #3303 * fix(ssr): normalize manifest filenames
1 parent 82c51ee commit 64ec27b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/plugin-vue-jsx/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
const babel = require('@babel/core')
33
const jsx = require('@vue/babel-plugin-jsx')
44
const importMeta = require('@babel/plugin-syntax-import-meta')
5-
const { createFilter } = require('@rollup/pluginutils')
5+
const { createFilter, normalizePath } = require('@rollup/pluginutils')
66
const hash = require('hash-sum')
7+
const path = require('path')
78

89
const ssrRegisterHelperId = '/__vue-jsx-ssr-register-helper'
910
const ssrRegisterHelperCode =
@@ -39,6 +40,7 @@ function ssrRegisterHelper(comp, filename) {
3940
* @returns {import('vite').Plugin}
4041
*/
4142
function vueJsxPlugin(options = {}) {
43+
let root = ''
4244
let needHmr = false
4345
let needSourceMap = true
4446

@@ -63,6 +65,7 @@ function vueJsxPlugin(options = {}) {
6365
configResolved(config) {
6466
needHmr = config.command === 'serve' && !config.isProduction
6567
needSourceMap = config.command === 'serve' || !!config.build.sourcemap
68+
root = config.root
6669
},
6770

6871
resolveId(id) {
@@ -226,9 +229,10 @@ function vueJsxPlugin(options = {}) {
226229
}
227230

228231
if (ssr) {
232+
const normalizedId = normalizePath(path.relative(root, id))
229233
let ssrInjectCode =
230234
`\nimport { ssrRegisterHelper } from "${ssrRegisterHelperId}"` +
231-
`\nconst __moduleId = ${JSON.stringify(id)}`
235+
`\nconst __moduleId = ${JSON.stringify(normalizedId)}`
232236
for (const { local } of hotComponents) {
233237
ssrInjectCode += `\nssrRegisterHelper(${local}, __moduleId)`
234238
}

packages/plugin-vue/src/main.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
setDescriptor
99
} from './utils/descriptorCache'
1010
import { PluginContext, TransformPluginContext } from 'rollup'
11+
import { normalizePath } from '@rollup/pluginutils'
1112
import { resolveScript } from './script'
1213
import { transformTemplateInMain } from './template'
1314
import { isOnlyTemplateChanged, isEqualBlock } from './handleHotUpdate'
@@ -143,13 +144,16 @@ export async function transformMain(
143144

144145
// SSR module registration by wrapping user setup
145146
if (ssr) {
147+
const normalizedFilename = normalizePath(
148+
path.relative(options.root, filename)
149+
)
146150
output.push(
147151
`import { useSSRContext as __vite_useSSRContext } from 'vue'`,
148152
`const _sfc_setup = _sfc_main.setup`,
149153
`_sfc_main.setup = (props, ctx) => {`,
150154
` const ssrContext = __vite_useSSRContext()`,
151155
` ;(ssrContext.modules || (ssrContext.modules = new Set())).add(${JSON.stringify(
152-
filename
156+
normalizedFilename
153157
)})`,
154158
` return _sfc_setup ? _sfc_setup(props, ctx) : undefined`,
155159
`}`

0 commit comments

Comments
 (0)