create-react-app: using non-npm dependencies / libraries


create-react-app: using non-npm dependencies / libraries



I'm using Create React App and I would like to use a JS library that isn't available via npm. How would I go about integrating that into my app? I think I can simply add a script tag for it in public/index.html for development purposes but I'm guessing that won't include it in the final build code. Any suggestions would be welcome.


public/index.html




1 Answer
1



You can add your script to the public folder and include it in the public/index.html file.


public


public/index.html


http://%PUBLIC_URL%/my-script.js





That appears to work - thanks! However, does that mean when I run npm run build, that this non-npm library will be included in my production ready code?
– Bill
Jun 29 at 21:44



npm run build





@Bill That's right. Everything in the public folder will be copied to the final build folder you use in production.
– Tholle
Jun 29 at 21:45


public


build





Ahh, OK. Thanks again for your help! As an old school jQuery developer, I'm finding this whole npm/webpack/build process daunting (and so far IMHO somewhat unnecessarily complicated). But I'm liking React.
– Bill
Jun 29 at 21:53





@Bill No problem! Yeah, it's quite the hassle in the beginning, but it's hard to go back to manually adding scripts when you get the hang of just npm i -S something, import Something from 'something';
– Tholle
Jun 29 at 21:55



npm i -S something


import Something from 'something';






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV