简体   繁体   English

如何在linux上不打开浏览器运行npm启动进行react开发

[英]How to run npm start without opening browser for react development on linux

I am learning react and find myself running npm start on the terminal a couple of times but its annoying how it opens a new browser window everytime.我正在学习反应并发现自己在终端上运行npm start几次,但它每次都打开新浏览器 window 的方式很烦人。 I'm trying to stop this from happening on linux.我试图阻止这种情况在 linux 上发生。

I found a solution for how to do this on Windows , but how can I do it on Linux?我在 Windows 上找到了如何执行此操作的解决方案,但如何在 Linux 上执行此操作?

Adding BROWSER=none to the .env file should get it solved.BROWSER=none添加到.env文件应该可以解决它。

If the folder /etc/profile.d doesn't exist create it.如果文件夹 /etc/profile.d 不存在,请创建它。 Then run touch /etc/profile.d/[any descriptive name here].sh and open it in the text editor of your choice.然后运行touch /etc/profile.d/[any descriptive name here].sh并在您选择的文本编辑器中打开它。 Then add export BROWSER=none there.然后在那里添加export BROWSER=none Then logout and login again.然后注销并再次登录。 If it didn't work then try putting export BROWSER="none" in the file .如果它不起作用,请尝试将export BROWSER="none" in the file This is setting an environment variable.这是设置环境变量。 Hope this helps.希望这可以帮助。

fixed固定的

create a .env file next to your package.json and put BROWSER=none inside在您的package.json旁边创建一个.env文件并将BROWSER=none放入

I don't think you need to run npm start so often.我认为您不需要经常运行npm start I've created my project via create-react-app which comes with Hot Module Reloading or HMR(restarts the server on any saved edit) in-built.我已经通过create-react-app创建了我的项目,它内置了热模块重新加载或 HMR(在任何保存的编辑上重新启动服务器)。

Starting a new React server multiple times can also be problematic as every time it will run on a different port.多次启动一个新的 React 服务器也会有问题,因为每次它都会在不同的端口上运行。 If you're integrating an API that has CORS set up for a particular port, it won't work on other instances.如果您正在集成一个 API,它为特定端口设置了 CORS,则它不会在其他实例上工作。

What to do?该怎么办?

  1. Create your application using create-react-app (cra) or add HMR using some library if you don't want to use cra .使用create-react-app (cra) 创建您的应用程序,或者如果您不想使用cra则使用一些库添加 HMR。 Here is a tutorial for that (haven't tested it).这是一个教程(尚未测试)。
  2. Always keep a single dev server running.始终保持单个开发服务器运行。 It will automatically reload on code change.它会在代码更改时自动重新加载。
  3. Stop the server by Ctrl + C when you don't want to use it.当您不想使用它时,按Ctrl + C停止服务器。

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

相关问题 是否可以在没有 npm start 的情况下运行 React 项目? - Is it possible to run React project without npm start? 如何在不打开浏览器的情况下在服务器中运行Slimmerjs? - How to run Slimmerjs in a server without opening a browser? 如何使用 npm 启动和 expo 启动来运行 React 本机 expo - How to run React native expo with npm start and expo start 运行`npm run start`后,create-react-app如何重用现有的Browser选项卡? - How does create-react-app re-use an existing Browser tab after running `npm run start`? npm start 是怎么运行的,应该是npm run start? (创建 React 应用程序) - How npm start works, it should be npm run start? (Create React App) 我可以在没有 npm 启动和 npx create-react-app 的情况下使用 React 运行 index.html 吗? - Can I run index.html with React without npm start and npx create-react-app? 如何使用 Chrome 浏览器运行 react-script start? - How do I run the react-script start with chrome browser? 如何运行“ npm start”永远运行 - How to run “npm start” run forever 基本解释了npm开始与我的reactjs代码有关以及如何从浏览器运行它 - basic explain for what does npm start do with my reactjs code and how to run it from browser create-react-app:如何使用特定浏览器“npm start”? - create-react-app: How do I "npm start" with a specific browser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM