Skip to content

Commit

Permalink
fix(ssr): normalize manifest filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdinando-ferreira committed Jun 7, 2021
1 parent 32c596c commit bdcaba6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/plugin-vue-jsx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const jsx = require('@vue/babel-plugin-jsx')
const importMeta = require('@babel/plugin-syntax-import-meta')
const { createFilter } = 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 @@ -217,9 +220,10 @@ function vueJsxPlugin(options = {}) {
}

if (ssr) {
const normalizedId = 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
3 changes: 2 additions & 1 deletion packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,14 @@ export async function transformMain(

// SSR module registration by wrapping user setup
if (ssr) {
const normalizedFilename = 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
5 changes: 4 additions & 1 deletion packages/vite/src/node/ssr/ssrManifestPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { relative } from 'path'
import { ResolvedConfig } from '..'
import { Plugin } from '../plugin'
import { chunkToEmittedCssFileMap } from '../plugins/css'
Expand All @@ -21,7 +22,9 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin {
: chunkToEmittedCssFileMap.get(chunk)
const assetFiles = chunkToEmittedAssetsMap.get(chunk)
for (const id in chunk.modules) {
const mappedChunks = ssrManifest[id] || (ssrManifest[id] = [])
const normalizedId = relative(config.root, id)
const mappedChunks =
ssrManifest[normalizedId] || (ssrManifest[normalizedId] = [])
if (!chunk.isEntry) {
mappedChunks.push(base + chunk.fileName)
}
Expand Down

0 comments on commit bdcaba6

Please sign in to comment.