create-react-app is showing all my code in production, how to hide it?

老子叫甜甜 提交于 2020-04-29 09:22:24

问题


In my chrome sources tab, I am able to view all my files by exact folder location. How can I hide them?

These weren't the problem in my previous project, which were made without using create-react-app.


回答1:


It seems to be correct behaviour in create-react-app according to Issue #1632.

Gaeron:

This is expected. You can delete .map files from the build output if you want to disable it, although you'll get console warnings about them missing.

There is no harm in leaving them in though in my opinion. Client code is already available to the user’s machine so there’s no secrets in it.

Maybe this is your case?

Also ensure you have proper production build, the output of npm run build/yarn build is the one which should be deployed to your server.




回答2:


Make this change in package.json file and you are good to go.

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



回答3:


Or you can use GENERATE_SOURCEMAP=false react-scripts build on linux/mac




回答4:


Delete all the .map files (from js/ and css/ folder) before uploading to the production server



来源:https://stackoverflow.com/questions/51415780/create-react-app-is-showing-all-my-code-in-production-how-to-hide-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!