Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hot module replacement for native ES Modules (browser or Node.js) *without* Webpack? No build tools

I'm looking to add HMR to plain Node.js code or browser code written with native ES Modules.

There's no Babel, no Webpack, no transpilation, just plain JS files and ES Module import and export calls.

Can we do HMR in plain Node or browser?

like image 218
trusktr Avatar asked May 28 '19 23:05

trusktr


People also ask

What is Webpack hot module replacement?

Hot Module Replacement (HMR) exchanges, adds, or removes modules while an application is running, without a full reload. This can significantly speed up development in a few ways: Retain application state which is lost during a full reload. Save valuable development time by only updating what's changed.

Which command helps to enable hot module replacement in the dev server?

You can use the CLI to modify the webpack-dev-server configuration with the following command: webpack serve --hot-only . Now let's update the index. js file so that when a change inside print. js is detected we tell webpack to accept the updated module.

What is hot module replacement in angular?

HRM is Webpack feature which is also used by Angular11 team since Angular build system is Webpack based. HRM feature enables development faster because it updates limited resource after you save code in project. To enable HMR using Angular 11 cli, following command need to be execute.


2 Answers

Here's a pure node HMR module from a developer/entrepreneur who i work with personally: https://github.com/huan/hot-import

Hope this helps.

like image 80
Bryan Huang Avatar answered Sep 19 '22 17:09

Bryan Huang


Snowpack is a tool which uses native ES modules to get rid of bundling and in each save changes will be reflected faster compared to setups using bundlers like Webpack.

From Snowpack website:

No More Bundling During Development: Snowpack installs your npm dependencies so that they can be imported directly in the browser without an application bundler.

Instant Dev Startup: Snowpack’s dev server starts up in less than 20ms on most machines. Files are only built on-demand, as requested by the browser.

Instant Dev Rebuilding: Never wait more than a few milliseconds when you hit save. Since there’s no large app chunks to rebuild, changes are reflected in the browser instantly.

Connect your Favorite Build Tools: Manage your build using a simple, familiar “scripts” interface that replaces traditionally complex plugin ecosystems.

Bundle for Production: It’s the best of both worlds: fast bundle-free development + optimized bundling in production. Choose between bundled (optimized) or unbundled build output without any additional config needed.

like image 37
Rajika Imal Avatar answered Sep 22 '22 17:09

Rajika Imal