@@ -7,10 +7,20 @@ import {
77} from '@vue/compiler-sfc'
88import { VueLoaderOptions } from 'src'
99
10- // since we generate different output based on whether the template is inlined
11- // or not, we need to cache the results separately
12- const inlinedCache = new WeakMap < SFCDescriptor , SFCScriptBlock | null > ( )
13- const normalCache = new WeakMap < SFCDescriptor , SFCScriptBlock | null > ( )
10+ const clientCache = new WeakMap < SFCDescriptor , SFCScriptBlock | null > ( )
11+ const serverCache = new WeakMap < SFCDescriptor , SFCScriptBlock | null > ( )
12+
13+ /**
14+ * inline template mode can only be enabled if:
15+ * - is production (separate compilation needed for HMR during dev)
16+ * - template has no pre-processor (separate loader chain required)
17+ * - template is not using src
18+ */
19+ export function canInlineTemplate ( descriptor : SFCDescriptor , isProd : boolean ) {
20+ const templateLang = descriptor . template && descriptor . template . lang
21+ const templateSrc = descriptor . template && descriptor . template . src
22+ return isProd && ! ! descriptor . scriptSetup && ! templateLang && ! templateSrc
23+ }
1424
1525export function resolveScript (
1626 descriptor : SFCDescriptor ,
@@ -24,10 +34,9 @@ export function resolveScript(
2434
2535 const isProd = loaderContext . mode === 'production'
2636 const isServer = loaderContext . target === 'node'
27- const templateLang = descriptor . template && descriptor . template . lang
28- const enableInline = isProd && ! isServer && ! templateLang
37+ const enableInline = canInlineTemplate ( descriptor , isProd )
2938
30- const cacheToUse = enableInline ? inlinedCache : normalCache
39+ const cacheToUse = isServer ? serverCache : clientCache
3140 const cached = cacheToUse . get ( descriptor )
3241 if ( cached ) {
3342 return cached
@@ -45,13 +54,14 @@ export function resolveScript(
4554 if ( compileScript ) {
4655 try {
4756 resolved = compileScript ( descriptor , {
48- // @ts -ignore TODO remove when vue is upgraded
49- scopeId,
57+ // @ts -ignore
58+ id : scopeId ,
5059 isProd,
5160 inlineTemplate : enableInline ,
5261 babelParserPlugins : options . babelParserPlugins ,
5362 templateOptions : {
5463 compiler,
64+ ssr : isServer ,
5565 transformAssetUrls : options . transformAssetUrls || true ,
5666 } ,
5767 } )
0 commit comments