Skip to content

Commit

Permalink
fix(ssr): normalize manifest filenames (#3706)
Browse files Browse the repository at this point in the history
* fix(ssr): normalize manifest filenames

Fixes #3303

* fix(ssr): normalize manifest filenames
  • Loading branch information
ferdinando-ferreira authored Jun 26, 2021
1 parent 82c51ee commit 64ec27b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/plugin-vue-jsx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
const babel = require('@babel/core')
const jsx = require('@vue/babel-plugin-jsx')
const importMeta = require('@babel/plugin-syntax-import-meta')
const { createFilter } = require('@rollup/pluginutils')
const { createFilter, normalizePath } = require('@rollup/pluginutils')
const hash = require('hash-sum')
const path = require('path')

const ssrRegisterHelperId = '/__vue-jsx-ssr-register-helper'
const ssrRegisterHelperCode =
Expand Down Expand Up @@ -39,6 +40,7 @@ function ssrRegisterHelper(comp, filename) {
* @returns {import('vite').Plugin}
*/
function vueJsxPlugin(options = {}) {
let root = ''
let needHmr = false
let needSourceMap = true

Expand All @@ -63,6 +65,7 @@ function vueJsxPlugin(options = {}) {
configResolved(config) {
needHmr = config.command === 'serve' && !config.isProduction
needSourceMap = config.command === 'serve' || !!config.build.sourcemap
root = config.root
},

resolveId(id) {
Expand Down Expand Up @@ -226,9 +229,10 @@ function vueJsxPlugin(options = {}) {
}

if (ssr) {
const normalizedId = normalizePath(path.relative(root, id))
let ssrInjectCode =
`\nimport { ssrRegisterHelper } from "${ssrRegisterHelperId}"` +
`\nconst __moduleId = ${JSON.stringify(id)}`
`\nconst __moduleId = ${JSON.stringify(normalizedId)}`
for (const { local } of hotComponents) {
ssrInjectCode += `\nssrRegisterHelper(${local}, __moduleId)`
}
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
setDescriptor
} from './utils/descriptorCache'
import { PluginContext, TransformPluginContext } from 'rollup'
import { normalizePath } from '@rollup/pluginutils'
import { resolveScript } from './script'
import { transformTemplateInMain } from './template'
import { isOnlyTemplateChanged, isEqualBlock } from './handleHotUpdate'
Expand Down Expand Up @@ -143,13 +144,16 @@ export async function transformMain(

// SSR module registration by wrapping user setup
if (ssr) {
const normalizedFilename = normalizePath(
path.relative(options.root, filename)
)
output.push(
`import { useSSRContext as __vite_useSSRContext } from 'vue'`,
`const _sfc_setup = _sfc_main.setup`,
`_sfc_main.setup = (props, ctx) => {`,
` const ssrContext = __vite_useSSRContext()`,
` ;(ssrContext.modules || (ssrContext.modules = new Set())).add(${JSON.stringify(
filename
normalizedFilename
)})`,
` return _sfc_setup ? _sfc_setup(props, ctx) : undefined`,
`}`
Expand Down

0 comments on commit 64ec27b

Please sign in to comment.