Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactjs:How to hide node modules and webconfig in the devtools on production app?

I've created a React.js application running npx create-react-app my-app and I don't want the complete project to be available in the devtools when in production mode.

How can I disable or hide node modules and webconfig in the sources tab(devtools)?

I checked in other deployed react application which does not show static folder or the entire project; how can I achieve same?

Below, a screenshot from the console of my browser's "Sources" tab, showing some directories I would like to hide to the public;

devtool image

like image 720
code_Knight Avatar asked Jun 11 '18 04:06

code_Knight


2 Answers

You see your full code in devtools because of source mapped files. It is a great way to debug your code in development or even for some people in production mode.

Without sourced maps, when an error occurs you can't easily find where this error is coming from in your bundled files. If you don't want to see your code like this in production you can simply delete the files after the built. Remove the .map files in your static/css and static/js folders. So, with this you can hide your unbundled source code. But, bundled .js and .css files will be always there. There is no way to hide them since this is frontend.

As told in the comments if your concern is really a security issue, then you can't do this on frontend. Your code always will be seen, at least its minified and uglified but there will be. So, do your security stuff in backend.

like image 77
devserkan Avatar answered Nov 16 '22 02:11

devserkan


GENERATE_SOURCEMAP=false react-scripts build

this will not generate sourcemap (.map) files in the final build.

like image 21
Abhijeet Avatar answered Nov 16 '22 02:11

Abhijeet