Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

feat(HMR): expose context #724

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bundle-config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ module.exports = function (source) {
require("nativescript-dev-webpack/hot")(__webpack_require__.h(), (fileName) => applicationFiles.getFile(fileName));
};

global.__hmrRefresh = function(type) {
global.__hmrRefresh = function({ type, module }) {
global.__hmrNeedReload = true;
setTimeout(() => {
if(global.__hmrNeedReload) {
global.__hmrNeedReload = false;
global.__hmrLivesyncBackup();
global.__hmrLivesyncBackup({ type, module });
}
});
}
Expand All @@ -45,9 +45,9 @@ module.exports = function (source) {
if (loadCss) {
source = `
require("${
angular ?
'nativescript-dev-webpack/load-application-css-angular' :
'nativescript-dev-webpack/load-application-css-regular'
angular ?
'nativescript-dev-webpack/load-application-css-angular' :
'nativescript-dev-webpack/load-application-css-regular'
}")();
${source}
`;
Expand Down
6 changes: 3 additions & 3 deletions hot-loader-helper.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports.reload = function(type) { return `
module.exports.reload = function ({ type, module }) {
return `
if (module.hot) {
module.hot.accept();
module.hot.dispose(() => {
global.__hmrRefresh('${type}');
global.__hmrRefresh({ type: '${type}', module: '${module}' });
})
}
`};

4 changes: 3 additions & 1 deletion markup-hot-loader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { reload } = require("./hot-loader-helper");

module.exports = function (source) {
return `${source};${reload('markup')}`;
const typeMarkup = "markup";
const modulePath = this.resourcePath.replace(this.context, ".");
return `${source};${reload({ type: typeMarkup, module: modulePath })}`;
};
4 changes: 3 additions & 1 deletion script-hot-loader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { reload } = require("./hot-loader-helper");

module.exports = function (source) {
return `${source};${reload('script')}`;
const typeScript = "script";
const modulePath = this.resourcePath.replace(this.context, ".");
return `${source};${reload({ type: typeScript, module: modulePath })}`;
};
4 changes: 3 additions & 1 deletion style-hot-loader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { reload } = require("./hot-loader-helper");

module.exports = function (source) {
return `${source};${reload('style')}`;
const typeStyle = "style";
const modulePath = this.resourcePath.replace(this.context, ".");
return `${source};${reload({ type: typeStyle, module: modulePath })}`;
};