[英]How do I load a React component through a JavaScript UMD?
I am trying to use the following external component in my React project.我正在尝试在我的 React 项目中使用以下外部组件。 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.
我的项目不是直接基于 npm 生态系统(我使用的是 react-dom),所以我一直在尝试使用静态编译的 JavaScript 文件导入组件,在我的 html 中带有常规脚本标记。
The file generated by the build seems to be a JavaScript UMD.构建生成的文件似乎是 JavaScript UMD。 I have tried to load this module using RequireJS, but I have been having the problem described here .
我曾尝试使用 RequireJS 加载此模块,但我遇到了此处描述的问题。
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.
我知道 Browserfy 执行与 RequireJS 类似的功能,但我什至不确定我是否应该将其作为可能的途径。
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 .作为参考,我发现这可以使用现有的库来完成,例如https://github.com/revolunet/react-umd-loader 。 Even if the libraries themselves are somewhat deprecated, the techniques used are still relevant.
即使库本身有些过时,所使用的技术仍然是相关的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.