我正在尝试让 HMR 为我的淘汰赛应用程序工作,并且目前正在努力让 HMR 重新加载,每当我更改viewModel
自身内部的某些内容时,但范围之外的任何内容都可以工作。
例子:
//hmr.js
require('mymodule');
if(module.hot)
module.hot.accept();
// mymodule.js
function myViewModel(params) {
console.log('this will only be logged once'); // This one doesn't change after saving
}
console.log('I can get this to be logged multiple times without reload');
module.exports = {
viewModel: myViewModel,
template: '<div>just some stuff here</div>'
};
我想知道我是否需要做其他事情来告诉 HMR 重新触发viewModel
? 目前在我的main.js
文件中,我ko.applyBindings(new AppViewModel());
只有一次被解雇,而且ko.components.register()
我的main.js
文件中也有需要在我的mymodule
文件中。