-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LiveReload always sends all assets #33
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/* jshint node:true */ | ||
var statSync = require('fs').statSync; | ||
var lr = require('tiny-lr'); | ||
var servers = {}; | ||
|
||
|
@@ -17,6 +18,10 @@ function LiveReloadPlugin(options) { | |
this.protocol = this.options.protocol ? this.options.protocol + ':' : ''; | ||
this.hostname = this.options.hostname || '" + location.hostname + "'; | ||
this.server = null; | ||
|
||
this.startTime = new Date(); | ||
this.startTime.setSeconds(-process.uptime()); | ||
this.prevTimestamps = {}; | ||
} | ||
|
||
function arraysEqual(a1, a2){ | ||
|
@@ -53,18 +58,52 @@ LiveReloadPlugin.prototype.start = function start(watching, cb) { | |
}; | ||
|
||
LiveReloadPlugin.prototype.done = function done(stats) { | ||
var timestamps = stats.compilation ? stats.compilation.fileTimestamps : {}; | ||
var assets = stats.compilation.assets; | ||
var include = []; | ||
|
||
// If no timestamp information is available, use all assets. | ||
if (!timestamps) { | ||
include.push.apply(include, Object.keys(assets)); | ||
} | ||
else { | ||
this.changedFiles = Object.keys(timestamps).filter(function(watchfile) { | ||
return this.startTime < Math.ceil(statSync(watchfile).mtime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Synchronously There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, and I suspect webpack has already stat'd these files at some other point. Wonder if there is a way to tap into a stat cache of some kind? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the webpack wiki you linked, it looks like they're using prevTimestamps as a way to see changes. var changedFiles = Object.keys(compilation.fileTimestamps).filter(function(watchfile) {
return (this.prevTimestamps[watchfile] || this.startTime) < (compilation.fileTimestamps[watchfile] || Infinity);
}.bind(this)); |
||
}.bind(this)).forEach(function(changedFile) { | ||
Object.keys(assets).forEach(function(assetName) { | ||
const asset = Object.assign({}, assets[assetName]); | ||
const sources = []; | ||
|
||
if (asset.emitted && asset.existsAt.split('.').slice(-1)[0] !== 'css') { | ||
include.push(assetName); | ||
} | ||
|
||
(asset.children || []).forEach(function(child) { | ||
if (child && child._sourceMap && child._sourceMap.sources) { | ||
sources.push.apply(sources, child._sourceMap.sources); | ||
} | ||
}); | ||
|
||
if (sources.includes(changedFile)) { | ||
include.push(assetName); | ||
} | ||
}, this); | ||
}, this); | ||
} | ||
|
||
this.startTime = Date.now(); | ||
|
||
var hash = stats.compilation.hash; | ||
var childHashes = (stats.compilation.children || []).map(child => child.hash); | ||
var files = Object.keys(stats.compilation.assets); | ||
var include = files.filter(function(file) { | ||
var updated = include.filter(function(file) { | ||
return !file.match(this.ignore); | ||
}, this); | ||
|
||
if (this.isRunning && (hash !== this.lastHash || !arraysEqual(childHashes, this.lastChildHashes)) && include.length > 0) { | ||
if (this.isRunning && (hash !== this.lastHash || !arraysEqual(childHashes, this.lastChildHashes)) && updated.length > 0) { | ||
this.lastHash = hash; | ||
this.lastChildHashes = childHashes; | ||
setTimeout(function onTimeout() { | ||
this.server.notifyClients(include); | ||
this.server.notifyClients(updated); | ||
}.bind(this), this.delay); | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no usage of
prevTimestamps