Where should I place a script in React/Redux?

326 Views Asked by At

I am very new to react/redux/node and I recently started learning them.

I am trying to write an application that would use OpenPGP.JS to provide encryption and decryption functions. While certain components within the application may need to call the script, which uses OpenPGP.js library for encryption, I am not sure about where to put the script.

Edit: The following is the current tree structure.

├── LICENSE.MD
├── README.md
├── index.html
├── package-lock.json
├── package.json
├── src
│   ├── actions
│   │   └── index.js
│   ├── components
│   │   └── app.js
│   ├── index.js
│   └── reducers
│       └── index.js
├── style
│   └── style.css
├── test
│   ├── components
│   │   └── app_test.js
│   └── test_helper.js
└── webpack.config.js

Any pointers would be helpful.

Workflow

1

There are 1 best solutions below

2
On

You can add client JavaScript to your package.json and install them with npm or yarn. Your directory structure does not show where openpgp is located but it should be in node_modules (also not in your directory structure).

Since you're using webpack you can just install it with npm or yarn (as documented):

npm install --save openpgp

Then require it in your script:

require openpgp from "openpgp"

If webpack complains because the github repo points to dist/openpgp.js you could try to add a resolve in your webpack.config.js that points to the src directory instead of the dist.