0

I have a React application, and I've noticed that when I open Chrome Developer Tools and go to the Sources tab, I can see a folder named static/js. Expanding this folder reveals the entire code of my React project. This seems concerning from a security perspective.

So I went with the GENERATE_SOURCEMAP=false and it works for me for .js files only. I can still see the .css files in the Sources tab in static folder.

build: set \"GENERATE_SOURCEMAP=false\" && react-scripts build

How can I achieve to minify the CSS files? Does GENERATE_SOURCEMAP minifies JS files only? How can I prevent the source code of my React app from being exposed in this manner? Is there a way to obfuscate or hide the code to enhance security?

2
  • 1
    Hello:) Are you sure that you are using the latest version of react? Because this issue was fixed in 2018. Here: github.com/facebook/create-react-app/pull/5246 Commented Aug 1, 2024 at 10:01
  • @AdamBasha I a using React version 17.0.2 Commented Aug 1, 2024 at 10:04

1 Answer 1

0

I achieved the result through the env file. I added one variable to .env file like below. After adding it to env file do not forget to update the env variable on your hosting platform as well. After adding this variable React will automatically take care of other things.

// .env

GENERATE_SOURCEMAP=false
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.