[英]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?该怎么办?
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).Ctrl + C
when you don't want to use it.Ctrl + C
停止服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.