Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
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

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

‎bundle-config-loader.js‎

Lines changed: 5 additions & 5 deletions
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
`;

‎hot-loader-helper.js‎

Lines changed: 3 additions & 3 deletions
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-

‎markup-hot-loader.js‎

Lines changed: 3 additions & 1 deletion
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
};

‎script-hot-loader.js‎

Lines changed: 3 additions & 1 deletion
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
};

‎style-hot-loader.js‎

Lines changed: 3 additions & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /