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

how to replace react because of global ? #2702

Closed
takegine opened this issue Nov 25, 2022 · 2 comments
Closed

how to replace react because of global ? #2702

takegine opened this issue Nov 25, 2022 · 2 comments

Comments

@takegine
Copy link

I have separately inculcated react (umd) in html, and react has been linked to the global. However, when you write code in src, you will automatically import react if you use useState or somthing else. So that the output ESM contains the sentence import {use state} from 'react'. How can I replace all the import * from 'react' in the output file with this. React.
Declaring that react global in dts is not a solution, because some dependency packages downloaded from npm also import react

@evanw
Copy link
Owner

evanw commented Nov 25, 2022

You can write a plugin that swaps the react package for a module that does module.exports = window.React. An example plugin is in this thread: #337 (comment)

@takegine
Copy link
Author

#337 (comment) it is helpful, thanks

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