How to Hide your React Source Code from Getting Displayed in Chrome Dev Tools when Deployed to Production

Do you know that when you deploy your React application which is created using create-react-app or your own webpack configuration to a live website like Netlify, Vercel, Heroku etc,

your entire source code is visible to everyone from the sources tab…


This content originally appeared on DEV Community and was authored by Yogesh Chavan

source_code.jpeg

Do you know that when you deploy your React application which is created using create-react-app or your own webpack configuration to a live website like Netlify, Vercel, Heroku etc,

your entire source code is visible to everyone from the sources tab of the dev tools.

This is not an issue with the create-react-app but all of the source code is added because of the source map which helps to easily identify the source of the bug that will occur on the live site in the future.

This is fine If the website source code is publicly available on GitHub.

But you definitely don't want everyone to see your entire source code If it's a private repository or you're working on a client project.

There is an easy way to fix it.

Create a file with the name .env in your project folder with the below code inside it:

GENERATE_SOURCEMAP=false

Now, when you run ??? ??? ????? or ???? ??? ????? command from the terminal, It will generate a ????? folder with minified files without a source map that you can deploy to the production.

Check out my this article to understand how to hide source map when using custom webpack configuration

Removing the source map also decreases the final bundle size of your application and so your application will load faster.

Thanks for reading!

Want to learn all ES6+ features in detail including let and const, promises, various promise methods, array and object destructuring, arrow functions, async/await, import and export and a whole lot more from scratch?

Check out my Mastering Modern JavaScript book. This book covers all the pre-requisites for learning React and helps you to become better at JavaScript and React.

Check out free preview contents of the book here.

Also, you can check out my free Introduction to React Router course to learn React Router from scratch.

Want to stay up to date with regular content regarding JavaScript, React, Node.js? Follow me on LinkedIn.


This content originally appeared on DEV Community and was authored by Yogesh Chavan


Print Share Comment Cite Upload Translate Updates
APA

Yogesh Chavan | Sciencx (2021-04-17T05:43:05+00:00) How to Hide your React Source Code from Getting Displayed in Chrome Dev Tools when Deployed to Production. Retrieved from https://www.scien.cx/2021/04/17/how-to-hide-your-react-source-code-from-getting-displayed-in-chrome-dev-tools-when-deployed-to-production/

MLA
" » How to Hide your React Source Code from Getting Displayed in Chrome Dev Tools when Deployed to Production." Yogesh Chavan | Sciencx - Saturday April 17, 2021, https://www.scien.cx/2021/04/17/how-to-hide-your-react-source-code-from-getting-displayed-in-chrome-dev-tools-when-deployed-to-production/
HARVARD
Yogesh Chavan | Sciencx Saturday April 17, 2021 » How to Hide your React Source Code from Getting Displayed in Chrome Dev Tools when Deployed to Production., viewed ,<https://www.scien.cx/2021/04/17/how-to-hide-your-react-source-code-from-getting-displayed-in-chrome-dev-tools-when-deployed-to-production/>
VANCOUVER
Yogesh Chavan | Sciencx - » How to Hide your React Source Code from Getting Displayed in Chrome Dev Tools when Deployed to Production. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/17/how-to-hide-your-react-source-code-from-getting-displayed-in-chrome-dev-tools-when-deployed-to-production/
CHICAGO
" » How to Hide your React Source Code from Getting Displayed in Chrome Dev Tools when Deployed to Production." Yogesh Chavan | Sciencx - Accessed . https://www.scien.cx/2021/04/17/how-to-hide-your-react-source-code-from-getting-displayed-in-chrome-dev-tools-when-deployed-to-production/
IEEE
" » How to Hide your React Source Code from Getting Displayed in Chrome Dev Tools when Deployed to Production." Yogesh Chavan | Sciencx [Online]. Available: https://www.scien.cx/2021/04/17/how-to-hide-your-react-source-code-from-getting-displayed-in-chrome-dev-tools-when-deployed-to-production/. [Accessed: ]
rf:citation
» How to Hide your React Source Code from Getting Displayed in Chrome Dev Tools when Deployed to Production | Yogesh Chavan | Sciencx | https://www.scien.cx/2021/04/17/how-to-hide-your-react-source-code-from-getting-displayed-in-chrome-dev-tools-when-deployed-to-production/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.