简体   繁体   English

JavaScript React 在源选项卡中隐藏源文件

[英]JavaScript React hiding source files in sources tab

I have recently developed a website, it's NodeJs (on Ubuntu) and running a React app.我最近开发了一个网站,它是 NodeJs(在 Ubuntu 上)并运行一个 React 应用程序。 The problem is, for example, on Chrome;例如,问题出在 Chrome 上; when you right-click on the website and check sources you can see the source codes and all the files.当您右键单击网站并检查源时,您可以看到源代码和所有文件。 I want to hide all of them.我想隐藏所有这些。

In this section, I want to hide the source codes (files) in the server.在本节中,我想隐藏服务器中的源代码(文件)。 在此处输入图片说明

I tried couple of solutions on the internet but none of them worked.我在互联网上尝试了几种解决方案,但都没有奏效。

For example,例如,

I've added "build": "GENERATE_SOURCEMAP=false react-scripts build", in package.json and then I did run pm2 reload (also yarn build etc)我在package.json添加了"build": "GENERATE_SOURCEMAP=false react-scripts build",然后我确实运行了pm2 reload (还有 yarn build 等)

I've created a file called .env and added this line GENERATE_SOURCEMAP=false in it.我创建了一个名为.env的文件,并在其中添加了这一行GENERATE_SOURCEMAP=false

None of them has worked.他们都没有工作。 My website is currently active right now and I want to hide source files, how can I hide these source files from sources tab so people can't see the source codes?我的网站目前处于活动状态,我想隐藏源文件,如何从源选项卡中隐藏这些源文件,以便人们看不到源代码?

After long research, I have found the solution.经过长时间的研究,我找到了解决方案。

  1. Create a file called .env in your project.在您的项目中创建一个名为.env的文件。 The name of the file is just .env .该文件的名称只是.env
  2. In that .env file put this line GENERATE_SOURCEMAP=false and save.在该.env文件中放置这一行GENERATE_SOURCEMAP=false并保存。
  3. Then, run npm run build or yarn build .然后,运行npm run buildyarn build
  4. This will generate a build folder for production.这将生成一个用于生产的build文件夹。 After that, depends on what you are using, run this build file for running the website.之后,取决于你使用的是什么,运行这个构建文件来运行网站。 For example, I'm using pm2 on my Ubuntu server, so I've used pm2 serve build 3000 --spa (my website is running on port 3000) Also be careful you are in the same path with the build folder.例如,我使用pm2我的Ubuntu的服务器上,所以我用pm2 serve build 3000 --spa (我的网站在端口3000上运行),另外要小心你是在用相同的路径build文件夹。

That's it .就是这样 Now all the source code files are gone and website works like a charm.现在所有的源代码文件都消失了,网站工作起来就像一个魅力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM