简体   繁体   中英

How do I load a React component through a JavaScript UMD?

I am trying to use the following external component in my React project. My project is not based directly on the npm ecosystem (I am using react-dom), so I have been trying to import the component using a static compiled JavaScript file with a regular script tag in my html.

The file generated by the build seems to be a JavaScript UMD. I have tried to load this module using RequireJS, but I have been having the problem described here .

I'm not really sure whether I am approaching this correctly. I know that Browserfy performs similar functions to RequireJS, but I'm not even certain whether I should be pursuing this as a possible avenue.

What is the canonical way to load a component like this into the browser?

This question may be a duplicate of this similar question , but it does not have any real answers.

For reference, I found that this can be done using existing libraries, such as https://github.com/revolunet/react-umd-loader . Even if the libraries themselves are somewhat deprecated, the techniques used are still relevant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM