Skip to content

Commit

Permalink
fix(plugin-vue): template src isn't working when script setup (#5418)
Browse files Browse the repository at this point in the history
  • Loading branch information
y1d7ng committed Nov 2, 2021
1 parent fa9ee58 commit 3f4cf82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
11 changes: 2 additions & 9 deletions packages/plugin-vue/src/main.ts
Expand Up @@ -10,7 +10,7 @@ import {
} from './utils/descriptorCache'
import { PluginContext, SourceMap, TransformPluginContext } from 'rollup'
import { normalizePath } from '@rollup/pluginutils'
import { resolveScript } from './script'
import { resolveScript, isUseInlineTemplate } from './script'
import { transformTemplateInMain } from './template'
import { isOnlyTemplateChanged, isEqualBlock } from './handleHotUpdate'
import { RawSourceMap, SourceMapConsumer, SourceMapGenerator } from 'source-map'
Expand Down Expand Up @@ -53,14 +53,7 @@ export async function transformMain(
)

// template
// Check if we can use compile template as inlined render function
// inside <script setup>. This can only be done for build because
// inlined template cannot be individually hot updated.
const useInlineTemplate =
!devServer &&
descriptor.scriptSetup &&
!(descriptor.template && descriptor.template.src)
const hasTemplateImport = descriptor.template && !useInlineTemplate
const hasTemplateImport = descriptor.template && !isUseInlineTemplate(descriptor, !devServer)

let templateCode = ''
let templateMap: RawSourceMap | undefined
Expand Down
13 changes: 12 additions & 1 deletion packages/plugin-vue/src/script.ts
Expand Up @@ -22,6 +22,17 @@ export function setResolvedScript(
;(ssr ? ssrCache : clientCache).set(descriptor, script)
}

// Check if we can use compile template as inlined render function
// inside <script setup>. This can only be done for build because
// inlined template cannot be individually hot updated.
export function isUseInlineTemplate(descriptor: SFCDescriptor, isProd: boolean): boolean {
return (
isProd &&
!!descriptor.scriptSetup &&
!descriptor.template?.src
)
}

export function resolveScript(
descriptor: SFCDescriptor,
options: ResolvedOptions,
Expand All @@ -43,7 +54,7 @@ export function resolveScript(
...options.script,
id: descriptor.id,
isProd: options.isProduction,
inlineTemplate: !options.devServer,
inlineTemplate: isUseInlineTemplate(descriptor, !options.devServer),
refTransform: options.refTransform !== false,
templateOptions: resolveTemplateCompilerOptions(descriptor, options, ssr),
// @ts-ignore TODO remove ignore when we support this in @vue/compiler-sfc
Expand Down

0 comments on commit 3f4cf82

Please sign in to comment.