babel / babel

🐠 Babel is a compiler for writing next generation JavaScript.
https://babel.dev
MIT License
43.2k stars 5.64k forks source link

Feature request: hot modules #8292

Open trusktr opened 6 years ago

trusktr commented 6 years ago

Feature Request

Is your feature request related to a problem? Please describe.

The problem is reloading code. Sometimes it is cumbersome to reload an app (f.e. an Electron app) and click your way back to the state you were at. It could involve login steps, and a slew of navigation and interactions.

There's tools like Webpack, but using Webpack negates the benefits of the native runtime require and simplicity that @babel/register affords.

Describe the solution you'd like

It'd be neat if there were some sort of hot-module feature for @babel/register. Is it possible?

Describe alternatives you've considered

The alternative is Webpack, with convoluted configuration compared to @babel/register, and the downside that import paths are fake because app code is bundled.

The upside of @babel/register is that import paths are real, they use native require, and we can therefore take advantage of require hooks and/or monkey patching Module.prototype.require to achieve certain things like dynamic passing of references based on import strings (f.e., between main process and renderer process of an Electron app).

Using native require gives us some superpowers we don't otherwise get very easily with Webpack. But, we lose the Webpack hot-module super power.

Teachability, Documentation, Adoption, Migration Strategy

I would be glad to help document this. Not sure what the API would be like yet though.

babel-bot commented 6 years ago

Hey @trusktr! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

loganfsmyth commented 6 years ago

I don't think there's anything here that would require it to be implemented as part of @babel/register. We hook into require() calls, but you could build another tool that just hooked into that the same way.