React source code visible ๐Ÿ˜ฒ

Do you know that when you deploy your React application which is created using ๐—ฐ๐—ฟ๐—ฒ๐—ฎ๐˜๐—ฒ-๐—ฟ๐—ฒ๐—ฎ๐—ฐ๐˜-๐—ฎ๐—ฝ๐—ฝ 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 developer toolbar as shown in the screenshot of this post.

This is not an issue with the ๐—ฐ๐—ฟ๐—ฒ๐—ฎ๐˜๐—ฒ-๐—ฟ๐—ฒ๐—ฎ๐—ฐ๐˜-๐—ฎ๐—ฝ๐—ฝ but all of the source code is added because of the source map

๐Ÿ˜ฒ๐Ÿ˜ฒ๐Ÿ˜ฒ

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

so 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.

Connect with me for more tech related information Twitter

32