- npm install
- npm run server
- npm run start
- modify src/page1/test1.ts; command + s; will see log changed.
Webpack does support HMR(Hot Module Replacement) for browser and nodejs. But for nodejs, HMR can only support poll instead of websocket officially.
- Create ws-client: ws://localhost:9000/ws.
- Receive hash message after code change.
- Fetch
localhost:9000/main.${hash}.hot-update.json
andlocalhost:9000/main.${hash}.hot-update.js
. - Save json and js object to cache.
- Invoke Webpack api: hot.module.check();
- Webpack HMR will require(
./.${hash}.json
) and require(./.${hash}.js
), hook require method and return from cache. - Then module.hot.dispose/accept... apis will be called to execute your logic!