In my browser(chrome) sources tab, i am able to view all my react js files , folder wise and in tree structure .
how do i hide them? , i worked with angular previously and didn’t face this issue with angular js
it is a big security issue for my site , all source code and logic clearly visible, please help ???
Kuldeep Baberwal Answered question October 21, 2023
When deploying a ReactJS application in production, it’s essential to take steps to secure your source code and prevent it from being viewed in network calls. Here are some best practices to achieve this:
- Optimize the Build Process:
- Ensure that you’re using the proper production build. Use
npm run build
oryarn build
to generate the optimized build that should be deployed to your server.
- Ensure that you’re using the proper production build. Use
- Remove Source Maps:
- Source maps are files that help with debugging. However, in production, you may want to disable them. You can do this by setting
GENERATE_SOURCEMAP=false
in your build scripts or using environment variables.
Example in
package.json with scripts property
: “scripts”: { “build”: “GENERATE_SOURCEMAP=false react-scripts build” } - Source maps are files that help with debugging. However, in production, you may want to disable them. You can do this by setting
- Handling .map Files:
- If you choose to remove source maps, be aware that you might get console warnings about them being missing. Decide whether to keep or remove these files based on your specific needs.
Hope this helps you, Happy coding !!
Kuldeep Baberwal Answered question October 21, 2023