Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

官方文档中写的一个demo,

// print.js
export default function printMe() {
    // console.log('I get called from print.js!'); 
    console.log('Updating print.js...');
}
// index.js
import printMe from './print.js';

if (module.hot) {
    module.hot.accept('./print.js', function() {
        printMe();
    })
}

当对print.js修改后,在module.hot.accept中注册的回调函数被调用。

我的困惑是,假设浏览器已经获取了修改后的print.js,可要使新的代码生效,就得重新调用一次__webpack_require__啊,这个例子中不重新加载index.js的情况下,回调函数中的printMe不还是旧的引用吗?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
649 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...