如何在React项目中使用CDN导入 [英] How to use CDN Imports in a React-Project

查看:1720
本文介绍了如何在React项目中使用CDN导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目基于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.

推荐答案

尝试了一些事情之后,我找到了该用例的解决方案。
我安装了此软件包 html-webpack-externals-plugin

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导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆