How to include custom JS files in to React create app

后端 未结 2 636
情深已故
情深已故 2021-01-31 21:20

I had js files under public folder i want to include these js files in to react components which are under src component folder in react create application?

2条回答
  •  孤独总比滥情好
    2021-01-31 22:09

    Please read Using the public Folder.

    In general we recommend installing packages from npm and using import to access them from the source. But if you must use a prebuilt JS file that you don’t want to import, you can add it to the public folder (for example, public/mylib.js) and then add this to public/index.html:

    
    

    Then you can access the global variable from your app, for example:

    const mylib = window.mylib;
    

    And then use it.

    Hope this helps!

提交回复
热议问题