@@ -7,10 +7,20 @@ import {
7
7
} from '@vue/compiler-sfc'
8
8
import { VueLoaderOptions } from 'src'
9
9
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
+ }
14
24
15
25
export function resolveScript (
16
26
descriptor : SFCDescriptor ,
@@ -24,10 +34,9 @@ export function resolveScript(
24
34
25
35
const isProd = loaderContext . mode === 'production'
26
36
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 )
29
38
30
- const cacheToUse = enableInline ? inlinedCache : normalCache
39
+ const cacheToUse = isServer ? serverCache : clientCache
31
40
const cached = cacheToUse . get ( descriptor )
32
41
if ( cached ) {
33
42
return cached
@@ -45,13 +54,14 @@ export function resolveScript(
45
54
if ( compileScript ) {
46
55
try {
47
56
resolved = compileScript ( descriptor , {
48
- // @ts -ignore TODO remove when vue is upgraded
49
- scopeId,
57
+ // @ts -ignore
58
+ id : scopeId ,
50
59
isProd,
51
60
inlineTemplate : enableInline ,
52
61
babelParserPlugins : options . babelParserPlugins ,
53
62
templateOptions : {
54
63
compiler,
64
+ ssr : isServer ,
55
65
transformAssetUrls : options . transformAssetUrls || true ,
56
66
} ,
57
67
} )
0 commit comments