Skip to content

Commit a02ea1b

Browse files
committed
fix(webpack): hmr handling
1 parent 9ba2421 commit a02ea1b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/webpack5/src/configuration/base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
102102
env.commonjs = true;
103103
}
104104

105+
if (env.hmr) {
106+
// HMR webpack should use CommonJS
107+
env.commonjs = true;
108+
}
109+
105110
// config.stats({
106111
// logging: 'verbose'
107112
// })

packages/webpack5/src/loaders/nativescript-hot-loader/hmr.runtime.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,19 @@ if (module.hot) {
105105
};
106106

107107
const hasUpdate = () => {
108-
return [
108+
// Prefer platform-agnostic JS hot-update manifests; fall back to JSON
109+
// if needed. On iOS, the .hot-update.js files are present under the
110+
// app folder (see platforms/ios <app>/bundle.*.hot-update.js), while on
111+
// Android the JSON manifests are used by HMR. Checking JS first keeps
112+
// behavior correct for iOS without regressing Android.
113+
const candidates = [
114+
`~/bundle.${__webpack_hash__}.hot-update.js`,
115+
`~/runtime.${__webpack_hash__}.hot-update.js`,
109116
`~/bundle.${__webpack_hash__}.hot-update.json`,
110117
`~/runtime.${__webpack_hash__}.hot-update.json`,
111-
].some((path) => requireExists(path));
118+
];
119+
120+
return candidates.some((path) => requireExists(path));
112121
};
113122

114123
if (global.__onLiveSync !== global[hmrRuntimeLastLiveSyncSymbol]) {

0 commit comments

Comments
 (0)