简体   繁体   English

如何让 npm 开始在 Chrome 上打开特定配置文件?

[英]How do I get npm start to open a specific profile on Chrome?

I have a separate Chrome profile to do development work in.我有一个单独的 Chrome 配置文件来进行开发工作。

When I run npm start it opens my default Chrome profile.当我运行npm start ,它会打开我的默认 Chrome 配置文件。

I'd like it to open my development profile.我希望它打开我的开发资料。

I've tried creating a .env file in the root of the project with the following in it我尝试在项目的根目录中创建一个.env文件,其中包含以下内容

REACT_APP_BROWSER=chrome
REACT_APP_BROWSER_ARGS=--profile-directory="Profile 1"

installing env-cmd and changing the start command in the scripts section of the package.json filepackage.json文件的脚本部分安装env-cmd并更改启动命令

"start": "env-cmd .env npm react-scripts start",

but when I run npm start I get the following error:但是当我运行npm start时出现以下错误:

alex@Alex-PC:~/code/udemy/grider/pics$ npm start

> pics@0.1.0 start /home/alex/code/udemy/grider/pics
> env-cmd .env npm react-scripts start

spawn .env ENOENT
npm ERR! code ELIFECYCLE
npm ERR! errno 130
npm ERR! pics@0.1.0 start: `env-cmd .env npm react-scripts start`
npm ERR! Exit status 130
npm ERR! 
npm ERR! Failed at the pics@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/alex/.npm/_logs/2020-12-04T22_27_25_381Z-debug.log

Am I even on the right track or have I went in completely the wrong direction?我是在正确的轨道上,还是完全走错了方向?

There is no need for any additional libraries.不需要任何额外的库。 It seems you are using react and react-scripts is already using dotenv as it can be seen here .看来您正在使用 react 并且react-scripts已经在使用dotenv ,可以在此处看到。 This also means that there is no addition needed to start script: "start": "react-scripts start" .这也意味着启动脚本不需要添加: "start": "react-scripts start"

Using dotenv you can just create a.env file in your root directory with the following options as it can be seen from here .使用 dotenv,您可以使用以下选项在根目录中创建一个 .env 文件,从这里可以看到。

.env .env

BROWSER=google-chrome
BROWSER_ARGS=--profile-directory="Profile 1"

Note: google-chrome on Linux / chrome on Windows for the BROWSER variable注意:Linux 上的google-chrome / Windows 上的chrome BROWSER变量

BUT the ISSUE with this seems to be that because of the space in the profile name, it will only be passed the part before the space.但是这个问题似乎是由于配置文件名称中的空格,它只会传递空格之前的部分。 Chrome uses an internal profile name for the profile directory and by default creates the internal profile name with space in them. Chrome 使用内部配置文件名称作为配置文件目录,默认情况下创建内部配置文件名称,其中包含空格。

There does not seem to be a way to pass the profile name with spaces in it (no matter if using quotes/escaped quotes/additional variables etc.) but I really hope I will stand corrected on this issue.似乎没有办法传递带有空格的配置文件名称(无论是否使用引号/转义引号/其他变量等),但我真的希望我能在这个问题上得到纠正。

A WORKAROUND to the spacing issue: Create a new profile name without space.间距问题的解决方法:创建一个没有空格的新配置文件名称。 This will happen automatically if you just run npm start and the profile name you assigned in the .env file does not match any of the ones already in your browser.如果您只运行npm start并且您在.env文件中分配的配置文件名称与浏览器中已有的配置文件名称不匹配,这将自动发生。 Afterwards just sync your account in it and use it as normal.之后只需在其中同步您的帐户并正常使用它。

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

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