问题描述
我的项目基于create-react-app,现在我想使用。他们的文档建议使用CDN加载模块,但我找不到任何NPM软件包。我现在的问题是:如何正确加载CDN?
My project is based on create-react-app and now I want to use Here Maps. Their documentation recommends loading the modules with CDN and I cant find any NPM packages for it. My question now is: how can I load the CDN properly?
我知道有可能将CDN链接放在index.html文件中,但这似乎不是我认为的正确解决方案。
I know there is the possibility to just put the CDN link inside my index.html file but this seems not to be the right solution I think.
推荐答案
尝试了一些事情之后,我找到了该用例的解决方案。
我安装了此软件包。
After trying some things out, I found a solution for this use case.I installed this package "html-webpack-externals-plugin".
您要做的就是阅读用例文档。还描述了 CDN用例。
All you have to do is read the documentation for your use case. The "CDN-Use-Case" is also described.
要从外部JS-API访问功能,必须放置一个窗口。例如,在函数的前面:
For accessing the functions from the external JS-API you have to put a "window." in front of the function for example like this:
const map = new window.H.Map();
希望这对某人有帮助!
Hope this helps somebody!
这篇关于如何在React项目中使用CDN导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!