Skip to content

Commit c4a13de

Browse files
author
Franck Freiburger
committed
wip(core): update cache hash keys
1 parent cb26adf commit c4a13de

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

src/createVue2SFCModule.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
/**
4646
* the version of the library
4747
*/
48-
import { version } from './index'
48+
import { version, vueVersion } from './index'
4949

5050
// @ts-ignore
5151
const targetBrowserBabelPluginsHash : string = hash(...Object.keys({ ...(typeof ___targetBrowserBabelPlugins !== 'undefined' ? ___targetBrowserBabelPlugins : {}) }));
@@ -94,8 +94,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
9494

9595
const customBlockCallbacks : (CustomBlockCallback|undefined)[] = customBlockHandler !== undefined ? await Promise.all( descriptor.customBlocks.map((block ) => customBlockHandler(block, filename, options)) ) : [];
9696

97-
const componentHash = hash(strFilename, version, targetBrowserBabelPluginsHash);
98-
const scopeId = `data-v-${componentHash}`;
97+
const scopeId = `data-v-${hash(strFilename)}`;
9998

10099
// hack: asynchronously preloads the language processor before it is required by the synchronous preprocessCustomRequire() callback, see below
101100
if ( descriptor.template && descriptor.template.lang )
@@ -132,7 +131,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
132131
await withCache(
133132
compiledCache,
134133
[
135-
componentHash,
134+
vueVersion,
136135
compileTemplateOptions.source,
137136
descriptor.template.lang,
138137
],
@@ -161,11 +160,14 @@ export async function createSFCModule(source : string, filename : AbstractPath,
161160
await withCache(
162161
compiledCache,
163162
[
164-
componentHash,
163+
vueVersion,
164+
isProd,
165+
devMode,
165166
src,
166167
descriptor.script.lang,
167168
additionalBabelParserPlugins,
168169
Object.keys(additionalBabelPlugins),
170+
targetBrowserBabelPluginsHash,
169171
],
170172
async ({ preventCache }) => {
171173

@@ -192,8 +194,15 @@ export async function createSFCModule(source : string, filename : AbstractPath,
192194
await withCache(
193195
compiledCache,
194196
[
195-
componentHash,
196-
compileTemplateOptions.source
197+
vueVersion,
198+
devMode,
199+
compileTemplateOptions.source,
200+
delimiters,
201+
whitespace,
202+
scopeId,
203+
additionalBabelParserPlugins,
204+
Object.keys(additionalBabelPlugins),
205+
targetBrowserBabelPluginsHash,
197206
],
198207
async ({ preventCache }) => {
199208

@@ -244,10 +253,12 @@ export async function createSFCModule(source : string, filename : AbstractPath,
244253
const style = await withCache(
245254
compiledCache,
246255
[
247-
componentHash,
256+
vueVersion,
248257
srcRaw,
249-
descStyle.lang
250-
],
258+
descStyle.lang,
259+
scopeId,
260+
descStyle.scoped,
261+
],
251262
async ({ preventCache }) => {
252263

253264
const src = processStyles !== undefined ? await processStyles(srcRaw, descStyle.lang, filename, options) : srcRaw;

src/createVue3SFCModule.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type PreprocessLang = SFCAsyncStyleCompileOptions['preprocessLang'];
4343
/**
4444
* the version of the library
4545
*/
46-
import { version } from './index'
46+
import { version, vueVersion } from './index'
4747

4848
// @ts-ignore
4949
const targetBrowserBabelPluginsHash : string = hash(...Object.keys({ ...(typeof ___targetBrowserBabelPlugins !== 'undefined' ? ___targetBrowserBabelPlugins : {}) }));
@@ -93,8 +93,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
9393

9494
const customBlockCallbacks : (CustomBlockCallback|undefined)[] = customBlockHandler !== undefined ? await Promise.all( descriptor.customBlocks.map((block) => customBlockHandler(block, filename, options)) ) : [];
9595

96-
const componentHash = hash(strFilename, version, targetBrowserBabelPluginsHash);
97-
const scopeId = `data-v-${componentHash}`;
96+
const scopeId = `data-v-${hash(strFilename)}`;
9897

9998
const hasScoped = descriptor.styles.some(e => e.scoped);
10099

@@ -146,13 +145,16 @@ export async function createSFCModule(source : string, filename : AbstractPath,
146145
await withCache(
147146
compiledCache,
148147
[
149-
componentHash,
148+
vueVersion,
149+
isProd,
150+
devMode,
150151
descriptor.script?.content,
151152
descriptor.script?.lang,
152153
descriptor.scriptSetup?.content,
153154
descriptor.scriptSetup?.lang,
154155
additionalBabelParserPlugins,
155156
Object.keys(additionalBabelPlugins),
157+
targetBrowserBabelPluginsHash,
156158
],
157159
async ({ preventCache }) => {
158160

@@ -201,12 +203,16 @@ export async function createSFCModule(source : string, filename : AbstractPath,
201203
await withCache(
202204
compiledCache,
203205
[
204-
componentHash,
206+
vueVersion,
207+
devMode,
205208
compileTemplateOptions.source,
206209
compileTemplateOptions.compilerOptions.delimiters,
207210
compileTemplateOptions.compilerOptions.whitespace,
208211
compileTemplateOptions.compilerOptions.scopeId,
209212
compileTemplateOptions.compilerOptions.bindingMetadata ? Object.entries(compileTemplateOptions.compilerOptions.bindingMetadata) : '',
213+
additionalBabelParserPlugins,
214+
Object.keys(additionalBabelPlugins),
215+
targetBrowserBabelPluginsHash,
210216
],
211217
async ({ preventCache }) => {
212218

@@ -247,9 +253,11 @@ export async function createSFCModule(source : string, filename : AbstractPath,
247253
await withCache(
248254
compiledCache,
249255
[
250-
componentHash,
256+
vueVersion,
251257
srcRaw,
252-
descStyle.lang
258+
descStyle.lang,
259+
scopeId,
260+
descStyle.scoped,
253261
],
254262
async ({ preventCache }) => {
255263

0 commit comments

Comments
 (0)