Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
fix: ensure HMR stays working in SSR (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
galvez authored Jan 3, 2022
1 parent e02fcb6 commit 2cb9e0f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
8 changes: 1 addition & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,7 @@ export function createVuePlugin(rawOptions: VueViteOptions = {}): Plugin {

if (!query.vue) {
// main request
return await transformMain(
code,
filename,
options,
transformOptions || {},
this
)
return await transformMain(code, filename, options, this)
}

const descriptor = getDescriptor(
Expand Down
7 changes: 2 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export async function transformMain(
code: string,
filePath: string,
options: ResolvedOptions,
transformOptions: any,
pluginContext: TransformPluginContext
) {
const descriptor = createDescriptor(code, filePath, options)
Expand Down Expand Up @@ -87,7 +86,7 @@ function __vue2_injectStyles (context) {
// code += `\n__component__.options.__file = ${JSON.stringify(filePath)}`
// }

if (!transformOptions.ssr && options.devServer && !options.isProduction) {
if (options.devServer && !options.isProduction) {
result += genHmrCode(
options.root,
descriptor.id,
Expand Down Expand Up @@ -250,7 +249,7 @@ function genHmrCode(
import __VUE_HMR_RUNTIME__ from ${JSON.stringify(vueHotReload)}
import vue from "vue"
__VUE_HMR_RUNTIME__.install(vue)
if(__VUE_HMR_RUNTIME__.compatible){
if(!import.meta.env.SSR && __VUE_HMR_RUNTIME__.compatible){
if (!__VUE_HMR_RUNTIME__.isRecorded(${idJSON})) {
__VUE_HMR_RUNTIME__.createRecord(${idJSON}, __component__.options)
}
Expand All @@ -268,8 +267,6 @@ if(__VUE_HMR_RUNTIME__.compatible){
})`
: ''
}
} else {
console.log("The hmr is not compatible.")
}`
}

Expand Down
2 changes: 0 additions & 2 deletions test/unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ describe('vite-plugin-vue2', () => {
// @ts-ignore need mock if it will be used in the future
devServer: {},
},
// @ts-ignore need mock if it will be used in the future
{},
{}
)
expect(scriptMap).toHaveProperty('file')
Expand Down

0 comments on commit 2cb9e0f

Please sign in to comment.