2
2
const babel = require ( '@babel/core' )
3
3
const jsx = require ( '@vue/babel-plugin-jsx' )
4
4
const importMeta = require ( '@babel/plugin-syntax-import-meta' )
5
- const { createFilter } = require ( '@rollup/pluginutils' )
5
+ const { createFilter, normalizePath } = require ( '@rollup/pluginutils' )
6
6
const hash = require ( 'hash-sum' )
7
+ const path = require ( 'path' )
7
8
8
9
const ssrRegisterHelperId = '/__vue-jsx-ssr-register-helper'
9
10
const ssrRegisterHelperCode =
@@ -39,6 +40,7 @@ function ssrRegisterHelper(comp, filename) {
39
40
* @returns {import('vite').Plugin }
40
41
*/
41
42
function vueJsxPlugin ( options = { } ) {
43
+ let root = ''
42
44
let needHmr = false
43
45
let needSourceMap = true
44
46
@@ -63,6 +65,7 @@ function vueJsxPlugin(options = {}) {
63
65
configResolved ( config ) {
64
66
needHmr = config . command === 'serve' && ! config . isProduction
65
67
needSourceMap = config . command === 'serve' || ! ! config . build . sourcemap
68
+ root = config . root
66
69
} ,
67
70
68
71
resolveId ( id ) {
@@ -226,9 +229,10 @@ function vueJsxPlugin(options = {}) {
226
229
}
227
230
228
231
if ( ssr ) {
232
+ const normalizedId = normalizePath ( path . relative ( root , id ) )
229
233
let ssrInjectCode =
230
234
`\nimport { ssrRegisterHelper } from "${ ssrRegisterHelperId } "` +
231
- `\nconst __moduleId = ${ JSON . stringify ( id ) } `
235
+ `\nconst __moduleId = ${ JSON . stringify ( normalizedId ) } `
232
236
for ( const { local } of hotComponents ) {
233
237
ssrInjectCode += `\nssrRegisterHelper(${ local } , __moduleId)`
234
238
}
0 commit comments