@@ -165,7 +165,7 @@ VueComponentCompiler = class VueCompo extends CachingCompiler {
165
165
166
166
addCompileResult ( inputFile , compileResult ) {
167
167
let inputFilePath = inputFile . getPathInPackage ( ) ;
168
- let vueId = Hash ( inputFile . getPackageName ( ) + ': ' + inputFile . getPathInPackage ( ) ) ;
168
+ let vueId = '__v ' + FileHash ( inputFile ) ; ;
169
169
let isDev = isDevelopment ( ) ;
170
170
171
171
// Style
@@ -203,6 +203,9 @@ VueComponentCompiler = class VueCompo extends CachingCompiler {
203
203
204
204
let templateHash ;
205
205
if ( compileResult . template ) {
206
+
207
+ templateHash = Hash ( compileResult . template ) ;
208
+
206
209
if ( vueVersion === 1 ) {
207
210
// Fix quotes
208
211
compileResult . template = compileResult . template . replace ( quoteReg , ''' ) . replace ( lineReg , '' ) ;
@@ -221,7 +224,6 @@ VueComponentCompiler = class VueCompo extends CachingCompiler {
221
224
js += `__vue_options__.staticRenderFns = [${ templateCompilationResult . staticRenderFns . map ( toFunction ) . join ( ',' ) } ];\n` ;
222
225
}
223
226
}
224
- templateHash = Hash ( compileResult . template ) ;
225
227
226
228
//console.log(`template hash: ${templateHash}`);
227
229
}
@@ -321,6 +323,7 @@ class Cache {
321
323
template : null ,
322
324
watcher : null ,
323
325
dependencyManager : null ,
326
+ filePath : getFullPathInApp ( inputFile ) ,
324
327
} ;
325
328
326
329
if ( isDevelopment ( ) ) {
@@ -355,20 +358,6 @@ class Cache {
355
358
class ComponentWatcher {
356
359
constructor ( cache ) {
357
360
this . cache = cache ;
358
-
359
- // Listener
360
- this . _fileChanged = _ . debounce ( Meteor . bindEnvironment ( ( event ) => {
361
- if ( event === 'change' ) {
362
- try {
363
- hotCompile . bind ( this ) ( ) ;
364
- } catch ( e ) {
365
- console . error ( e ) ;
366
- }
367
- }
368
- } ) , 100 , {
369
- leading : true ,
370
- trailing : false
371
- } ) ;
372
361
}
373
362
374
363
update ( inputFile ) {
@@ -392,25 +381,38 @@ class ComponentWatcher {
392
381
}
393
382
394
383
_watchPath ( filePath ) {
384
+ var inputFile = this . inputFile ;
385
+ var cache = this . cache ;
395
386
if ( ! this . watcher || filePath !== this . filePath ) {
396
387
// Fast file change detection
397
388
this . _closeWatcher ( ) ;
398
389
this . watcher = fs . watch ( filePath , {
399
390
persistent : false
400
- } , this . _fileChanged ) ;
391
+ } , _ . debounce ( Meteor . bindEnvironment ( ( event ) => {
392
+ if ( event === 'change' ) {
393
+ try {
394
+ hotCompile ( filePath , inputFile , cache ) ;
395
+ } catch ( e ) {
396
+ console . error ( e ) ;
397
+ }
398
+ }
399
+ } ) , 100 , {
400
+ leading : true ,
401
+ trailing : false
402
+ } ) ) ;
401
403
this . watcher . on ( 'error' , ( error ) => console . error ( error ) ) ;
402
404
}
403
405
this . filePath = filePath ;
404
406
}
405
407
}
406
408
407
- function hotCompile ( ) {
408
- let inputFilePath = this . inputFile . getPathInPackage ( ) ;
409
- let contents = Plugin . fs . readFileSync ( this . filePath , {
409
+ function hotCompile ( filePath , inputFile , cache ) {
410
+ let inputFilePath = inputFile . getPathInPackage ( ) ;
411
+ let contents = Plugin . fs . readFileSync ( filePath , {
410
412
encoding : 'utf8'
411
413
} ) ;
412
- let compileResult = compileOneFileWithContents ( this . inputFile , contents , babelOptions ) ;
413
- let vueId = Hash ( this . inputFile . getPackageName ( ) + ': ' + this . inputFile . getPathInPackage ( ) ) ;
414
+ let compileResult = compileOneFileWithContents ( inputFile , contents , babelOptions ) ;
415
+ let vueId = '__v ' + FileHash ( inputFile ) ;
414
416
415
417
// CSS
416
418
let css = '' ;
@@ -422,7 +424,7 @@ function hotCompile() {
422
424
423
425
// Hot-reloading
424
426
cssHash = Hash ( css ) ;
425
- if ( this . cache . css !== cssHash ) {
427
+ if ( cache . css !== cssHash ) {
426
428
global . _dev_server . __addStyle ( { hash : vueId , css } ) ;
427
429
}
428
430
}
@@ -434,11 +436,13 @@ function hotCompile() {
434
436
let templateHash ;
435
437
if ( template ) {
436
438
templateHash = Hash ( template ) ;
439
+ } else {
440
+ templateHash = cache . template ;
437
441
}
438
442
439
- if ( this . cache . js !== jsHash || this . cache . template !== templateHash ) {
443
+ if ( cache . js !== jsHash || cache . template !== templateHash ) {
440
444
441
- const path = ( this . inputFile . getPackageName ( ) ? `packages/${ this . inputFile . getPackageName ( ) } ` : '' ) + this . inputFile . getPathInPackage ( ) ;
445
+ const path = ( inputFile . getPackageName ( ) ? `packages/${ inputFile . getPackageName ( ) } ` : '' ) + inputFile . getPathInPackage ( ) ;
442
446
443
447
// Require to absolute
444
448
js = js . replace ( requireRelativeFileReg , `require('/${ inputFilePath } /` ) ;
@@ -454,13 +458,13 @@ function hotCompile() {
454
458
if ( template ) {
455
459
if ( vueVersion === 1 ) {
456
460
// Fix quotes
457
- compileResult . template = compileResult . template . replace ( quoteReg , ''' ) . replace ( lineReg , '' ) ;
458
- js += "__vue_template__ = '" + compileResult . template + "';" ;
461
+ template = template . replace ( quoteReg , ''' ) . replace ( lineReg , '' ) ;
462
+ js += "__vue_template__ = '" + template + "';" ;
459
463
460
464
// Template option
461
465
js += `__vue_options__.template = __vue_template__;` ;
462
466
} else if ( vueVersion === 2 ) {
463
- const templateCompilationResult = templateCompiler . compile ( compileResult . template ) ;
467
+ const templateCompilationResult = templateCompiler . compile ( template ) ;
464
468
if ( templateCompilationResult . errors && templateCompilationResult . errors . length !== 0 ) {
465
469
console . error ( templateCompilationResult . errors ) ;
466
470
js += `__vue_options__.render = function(){};\n` ;
@@ -472,7 +476,7 @@ function hotCompile() {
472
476
}
473
477
}
474
478
475
- if ( vueVersion === 2 && this . cache . js === jsHash ) {
479
+ if ( vueVersion === 2 && cache . js === jsHash ) {
476
480
global . _dev_server . emit ( 'render' , { hash : vueId , template :`{
477
481
render: ${ render } ,
478
482
staticRenderFns: ${ staticRenderFns }
@@ -484,7 +488,7 @@ function hotCompile() {
484
488
}
485
489
486
490
// Package context
487
- js += `__vue_options__.packageName = '${ this . inputFile . getPackageName ( ) } ';` ;
491
+ js += `__vue_options__.packageName = '${ inputFile . getPackageName ( ) } ';` ;
488
492
489
493
// Export
490
494
js += `module.export('default', exports.default = __vue_script__);` ;
@@ -494,9 +498,9 @@ function hotCompile() {
494
498
}
495
499
496
500
// Cache
497
- this . cache . js = jsHash ;
498
- this . cache . css = cssHash ;
499
- this . cache . template = templateHash ;
501
+ cache . js = jsHash ;
502
+ cache . css = cssHash ;
503
+ cache . template = templateHash ;
500
504
}
501
505
502
506
class DependencyWatcher {
0 commit comments