Skip to content

Commit

Permalink
Reload html on change (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raathigesh authored and devongovett committed Dec 11, 2017
1 parent 9d319af commit 0ff76be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/HMRServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,29 @@ class HMRServer {
});
}

this.broadcast({
type: 'update',
assets: assets.map(asset => {
let deps = {};
for (let dep of asset.dependencies.values()) {
let mod = asset.depAssets.get(dep.name);
deps[dep.name] = mod.id;
}
const containsHtmlAsset = assets.some(asset => asset.type === "html");
if (containsHtmlAsset) {
this.broadcast({
type: 'reload'
});
} else {
this.broadcast({
type: 'update',
assets: assets.map(asset => {
let deps = {};
for (let dep of asset.dependencies.values()) {
let mod = asset.depAssets.get(dep.name);
deps[dep.name] = mod.id;
}

return {
id: asset.id,
generated: asset.generated,
deps: deps
};
})
});
return {
id: asset.id,
generated: asset.generated,
deps: deps
};
})
});
}
}

broadcast(msg) {
Expand Down
4 changes: 4 additions & 0 deletions src/builtins/hmr-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ if (!module.bundle.parent) {
}
}

if (data.type === 'reload') {
window.location.reload();
}

if (data.type === 'error-resolved') {
console.log('[parcel] ✨ Error resolved');
}
Expand Down

0 comments on commit 0ff76be

Please sign in to comment.