Search code examples
reactjscdncreate-react-app

How to use CDN Imports in a React-Project


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?

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.


Solution

  • After trying some things out, I found a solution for this use case. I installed this package "html-webpack-externals-plugin".

    All you have to do is read the documentation for your use case. The "CDN-Use-Case" is also described.

    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!