Sinny
Sinny

Reputation: 167

How do prevent my ReactJs code to be visible on client side?

Whoever accesses my react application can see all the used code in their browsers for example in 'Sources' when opening developers tools on google chrome. How can I hide it - is there any simple solution for that? Please notice that I also tried it with production build but the code is still visible.

Upvotes: 0

Views: 274

Answers (1)

Sumanth Madishetty
Sumanth Madishetty

Reputation: 3605

That is due to .map files generated in the build, They help in debugging the code in production and used to have stack trace in error loggers like Sentry etc

You can prevent .map files from being generated by setting GENERATE_SOURCEMAP as false

you can do that by modifying the build script in package.json as,

"build": "GENERATE_SOURCEMAP=false react-scripts build"

or you can keep it in .env file if you have

In .env insert the following line

GENERATE_SOURCEMAP=false

PS: .env file must me at the root of the project

Upvotes: 2

Related Questions