From 7f7e9137d71d888b40da2ec283aab5f85589761e Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 Jan 2021 12:35:31 -0500 Subject: [PATCH] feat(plugin-vue): support for vite core new ssr impl --- packages/plugin-vue/src/handleHotUpdate.ts | 6 ++++- packages/plugin-vue/src/index.ts | 23 +++++++++---------- packages/plugin-vue/src/main.ts | 26 +++++++++++++--------- packages/plugin-vue/src/script.ts | 15 +++++++------ packages/plugin-vue/src/template.ts | 24 +++++++++++--------- 5 files changed, 54 insertions(+), 40 deletions(-) diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index be131824..734c6d4a 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -55,7 +55,11 @@ export async function handleHotUpdate({ // metadata will not be available since the script part isn't loaded. // in this case, reuse the compiled script from previous descriptor. if (mainModule && !affectedModules.has(mainModule)) { - setResolvedScript(descriptor, getResolvedScript(prevDescriptor)!) + setResolvedScript( + descriptor, + getResolvedScript(prevDescriptor, false)!, + false + ) } affectedModules.add(templateModule) needRerender = true diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index d7155d52..240d49a0 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -37,7 +37,6 @@ export interface Options { include?: string | RegExp | (string | RegExp)[] exclude?: string | RegExp | (string | RegExp)[] - ssr?: boolean isProduction?: boolean // options to pass on to @vue/compiler-sfc @@ -53,7 +52,6 @@ export interface ResolvedOptions extends Options { export default function vuePlugin(rawOptions: Options = {}): Plugin { let options: ResolvedOptions = { - ssr: false, isProduction: process.env.NODE_ENV === 'production', ...rawOptions, root: process.cwd() @@ -75,11 +73,12 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { }, config(config) { - // provide default values for vue runtime esm defines - config.define = { - __VUE_OPTIONS_API__: true, - __VUE_PROD_DEVTOOLS__: false, - ...config.define + return { + define: { + __VUE_OPTIONS_API__: true, + __VUE_PROD_DEVTOOLS__: false + }, + ssrExternal: ['vue', '@vue/server-renderer'] } }, @@ -102,7 +101,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { } }, - load(id) { + load(id, ssr = false) { const { filename, query } = parseVueRequest(id) // select corresponding block for subpart virtual modules if (query.vue) { @@ -113,7 +112,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { let block: SFCBlock | null | undefined if (query.type === 'script') { // handle +