Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Babel plugin usage in an external toolkit by hard-coding react-stand-in constant #807

Closed
insin opened this issue Jan 20, 2018 · 8 comments

Comments

@insin
Copy link
Contributor

insin commented Jan 20, 2018

REGENERATE_METHOD is currently imported from react-stand-in

const { REGENERATE_METHOD } = require('react-stand-in')

This makes it difficult to extract use of react-hot-loader in your development setup to an external toolkit module, as you can't alias the modules imported by a Babel plugin and react-stand-in imports react.

Hard-coding this constant instead makes it possible to use the Babel plugin for this use-case:

const REGENERATE_METHOD = '__reactstandin__regenerateByEval';

Do you have any objections to hard-coding this constant instead?

@insin insin mentioned this issue Jan 20, 2018
8 tasks
@theKashey
Copy link
Collaborator

Not sure I understand the problem, but it is clear how to solve it.

@theKashey
Copy link
Collaborator

I've tried to solve this issue by using preval, but it could not import react-stand-in, as long it gonna to be build after the react-hot-loader.

So - just hardcoding constant and adding a test to secure the name.

@insin
Copy link
Contributor Author

insin commented Jan 21, 2018

Nice, thank you!

@theKashey
Copy link
Collaborator

@insin - beta 16 just got released. Please check that it fulfils your requirements.

@insin
Copy link
Contributor Author

insin commented Jan 21, 2018

It works beautifully, thanks: I can now externalise all the react-hot-loader config I need, so I don't need to install development-only dependencies in my app, or runtime dependencies in my development config 👍

@theKashey
Copy link
Collaborator

But you have to entangle your application's code with our, like AppContainer or hot?

@insin
Copy link
Contributor Author

insin commented Jan 22, 2018

No, I use react-hot-loader-loader to add the hot call to the main app module only when serving the app in development mode.

The react-hot-loader dependency is managed by nwb, so with this change in place I can now point to the absolute path to the react-hot-loader/babel plugin and alias react-hot-loader in my Webpack config so the generated code can resolve it: https://github.com/insin/nwb/blob/58ab23b8a30d0f3d5f870ba2d78436b4c0e8f226/src/react/index.js#L114-L139

@theKashey
Copy link
Collaborator

Wow, and then magic happens.
Oh, how I wish react-hot-loader-loader to handle async chunks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants