22const babel = require ( '@babel/core' )
33const jsx = require ( '@vue/babel-plugin-jsx' )
44const importMeta = require ( '@babel/plugin-syntax-import-meta' )
5- const { createFilter } = require ( '@rollup/pluginutils' )
5+ const { createFilter, normalizePath } = require ( '@rollup/pluginutils' )
66const hash = require ( 'hash-sum' )
7+ const path = require ( 'path' )
78
89const ssrRegisterHelperId = '/__vue-jsx-ssr-register-helper'
910const ssrRegisterHelperCode =
@@ -39,6 +40,7 @@ function ssrRegisterHelper(comp, filename) {
3940 * @returns {import('vite').Plugin }
4041 */
4142function 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 }
0 commit comments