Skip to content

Commit 3608916

Browse files
author
Guillaume Chau
committed
Merge branch 'modules-cache'
2 parents 50e0300 + d727990 commit 3608916

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

packages/vue-component/plugin/vue-compiler.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,21 @@ VueComponentCompiler = class VueCompo extends CachingCompiler {
161161
const lazyCSS = !isDev && isLazy && inputFile.getArch().indexOf('web') !== -1
162162

163163
// Style
164-
let css = ''
165-
let cssHash = ''
164+
let css = '';
165+
let cssHash = '';
166+
let cssModulesHash = '';
166167
if (compileResult.styles.length !== 0) {
167168
for (let style of compileResult.styles) {
168169
css += style.css
169170
}
170171

171172
cssHash = Hash(css)
172173

174+
//console.log(`css hash: ${cssHash}`);
175+
176+
if (compileResult.cssModules) {
177+
cssModulesHash = Hash(JSON.stringify(compileResult.cssModules));
178+
}
173179
//console.log(`css hash: ${cssHash}`)
174180
if (lazyCSS) {
175181
// Wrap CSS in Meteor's lazy CSS loader
@@ -214,12 +220,13 @@ VueComponentCompiler = class VueCompo extends CachingCompiler {
214220
}
215221

216222
if (isDev) {
217-
cache = Cache.getCache(inputFile)
218-
cache.watcher.update(inputFile)
219-
cache.filePath = getFilePath(inputFile)
220-
cache.js = jsHash
221-
cache.css = cssHash
222-
cache.template = templateHash
223+
cache = Cache.getCache(inputFile);
224+
cache.watcher.update(inputFile);
225+
cache.filePath = getFilePath(inputFile);
226+
cache.js = jsHash;
227+
cache.css = cssHash;
228+
cache.cssModules = cssModulesHash;
229+
cache.template = templateHash;
223230
}
224231
}
225232

@@ -358,7 +365,7 @@ const hotCompile = Meteor.bindEnvironment(function hotCompile(filePath, inputFil
358365
let vueId = compileResult.hash
359366

360367
// CSS
361-
let css = '', cssHash = ''
368+
let css = '', cssHash = '', cssModulesHash = '';
362369
if(parts.style) {
363370
if (compileResult.styles.length !== 0) {
364371
for (let style of compileResult.styles) {
@@ -370,6 +377,10 @@ const hotCompile = Meteor.bindEnvironment(function hotCompile(filePath, inputFil
370377
if (cache.css !== cssHash) {
371378
global._dev_server.__addStyle({ hash: vueId, css, path: inputFilePath })
372379
}
380+
381+
if (compileResult.cssModules) {
382+
cssModulesHash = Hash(JSON.stringify(compileResult.cssModules));
383+
}
373384
}
374385
}
375386

@@ -389,13 +400,13 @@ const hotCompile = Meteor.bindEnvironment(function hotCompile(filePath, inputFil
389400
}
390401
}
391402

392-
if (cache.js !== jsHash || cache.template !== templateHash) {
403+
if (cache.js !== jsHash || cache.template !== templateHash || cache.cssModules !== cssModulesHash) {
393404

394405
const path = (inputFile.getPackageName() ? `packages/${inputFile.getPackageName()}` : '') + inputFile.getPathInPackage()
395406

396407
const { js, render, staticRenderFns } = generateJs(vueId, inputFile, compileResult, true)
397408

398-
if(vueVersion === 2 && cache.js === jsHash) {
409+
if(vueVersion === 2 && cache.js === jsHash && cache.cssModules === cssModulesHash) {
399410
global._dev_server.emit('render', { hash: vueId, template:`{
400411
render: ${render},
401412
staticRenderFns: ${staticRenderFns}
@@ -411,7 +422,8 @@ const hotCompile = Meteor.bindEnvironment(function hotCompile(filePath, inputFil
411422
cache.js = jsHash
412423
}
413424
if(parts.style) {
414-
cache.css = cssHash
425+
cache.css = cssHash;
426+
cache.cssModules = cssModulesHash;
415427
}
416428
if(parts.template) {
417429
cache.template = templateHash

0 commit comments

Comments
 (0)