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

Commit c14110c

Browse files
vchimevSvetoslavTsenov
authored andcommitted
feat(HMR): expose context (#724)
The context consists of an object with `type` and `module` properties: - `type` could be `markup`, `script` or `style` - `module` is the path to the module
1 parent a2246f9 commit c14110c

5 files changed

+17
-11
lines changed

Diff for: bundle-config-loader.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ module.exports = function (source) {
1919
require("nativescript-dev-webpack/hot")(__webpack_require__.h(), (fileName) => applicationFiles.getFile(fileName));
2020
};
2121
22-
global.__hmrRefresh = function(type) {
22+
global.__hmrRefresh = function({ type, module }) {
2323
global.__hmrNeedReload = true;
2424
setTimeout(() => {
2525
if(global.__hmrNeedReload) {
2626
global.__hmrNeedReload = false;
27-
global.__hmrLivesyncBackup();
27+
global.__hmrLivesyncBackup({ type, module });
2828
}
2929
});
3030
}
@@ -45,9 +45,9 @@ module.exports = function (source) {
4545
if (loadCss) {
4646
source = `
4747
require("${
48-
angular ?
49-
'nativescript-dev-webpack/load-application-css-angular' :
50-
'nativescript-dev-webpack/load-application-css-regular'
48+
angular ?
49+
'nativescript-dev-webpack/load-application-css-angular' :
50+
'nativescript-dev-webpack/load-application-css-regular'
5151
}")();
5252
${source}
5353
`;

Diff for: hot-loader-helper.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
module.exports.reload = function(type) { return `
1+
module.exports.reload = function ({ type, module }) {
2+
return `
23
if (module.hot) {
34
module.hot.accept();
45
module.hot.dispose(() => {
5-
global.__hmrRefresh('${type}');
6+
global.__hmrRefresh({ type: '${type}', module: '${module}' });
67
})
78
}
89
`};
9-

Diff for: markup-hot-loader.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { reload } = require("./hot-loader-helper");
22

33
module.exports = function (source) {
4-
return `${source};${reload('markup')}`;
4+
const typeMarkup = "markup";
5+
const modulePath = this.resourcePath.replace(this.context, ".");
6+
return `${source};${reload({ type: typeMarkup, module: modulePath })}`;
57
};

Diff for: script-hot-loader.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { reload } = require("./hot-loader-helper");
22

33
module.exports = function (source) {
4-
return `${source};${reload('script')}`;
4+
const typeScript = "script";
5+
const modulePath = this.resourcePath.replace(this.context, ".");
6+
return `${source};${reload({ type: typeScript, module: modulePath })}`;
57
};

Diff for: style-hot-loader.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { reload } = require("./hot-loader-helper");
22

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

0 commit comments

Comments
 (0)