https://github.com/tanpuer/node-hmr
https://github.com/tanpuer/node-hmr
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tanpuer/node-hmr
- Owner: tanpuer
- Created: 2024-02-23T09:18:32.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-25T12:53:50.000Z (about 1 year ago)
- Last Synced: 2025-01-24T18:33:59.598Z (4 months ago)
- Language: TypeScript
- Size: 170 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
### nodejs-webpack-hmr
1. npm install
2. npm run server
3. npm run start
4. modify src/page1/test1.ts; command + s; will see log changed.##### background
Webpack does support HMR(Hot Module Replacement) for browser and nodejs.
But for nodejs, HMR can only support poll instead of websocket officially.##### ws
1. Create ws-client: ws://localhost:9000/ws.
2. Receive hash message after code change.
3. Fetch `localhost:9000/main.${hash}.hot-update.json` and `localhost:9000/main.${hash}.hot-update.js`.
4. Save json and js object to cache.
5. Invoke Webpack api: hot.module.check();
6. Webpack HMR will require(`./.${hash}.json`) and require(`./.${hash}.js`), hook require method and return from cache.
7. Then module.hot.dispose/accept... apis will be called to execute your logic!