简体   繁体   中英

Where should a compiled script be placed in React?

I am trying to include client side library ( OpenPGP.js ) in my react application to allow multiple react components to interact with OpenPGP.js via utility functions. Where should I place the script tag <script src="https://cdnjs.cloudflare.com/ajax/libs/openpgp/2.5.11/openpgp.js"></script> ? Also, where should I write my utility functions (as shown in https://github.com/openpgpjs/openpgpjs#examples ) such that they are accessible to all my components?

Why don't you consider using npm install --save openpgp ?. If you are you using npm for your project?

Then you can import it in any component like below

import openpgp from 'openpgp';

and use it like below.

openpgp.initWorker({ path:'openpgp.worker.js' });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM