使用一个 NPM 命令启动 react-create-app 和 Electron.js [英] Start react-create-app and Electron.js with one NPM command
问题描述
我有简单的自定义启动包 react-create-app
和 Electron.js
.我已添加到 package.json 文件中:
I have simple custom starter pack react-create-app
and Electron.js
.
I have added to package.json file:
"scripts": {
"electron": "electron .",
"start": "cross-env BROWSER=none react-scripts start",
....
我可以使用 npm run electron
启动 Electron 并使用 - npm start
进行反应.
and I can start Electron with npm run electron
and React with - npm start
.
我想要的是只用一个命令来启动 React 和 Electron:npm run both
.
What I want is to start React and Electron just with one command like: npm run both
.
我试过了:
"both": ""npm start" "npm run electron "",
但我在日志文件中收到错误:
but I am getting an error in a log file:
退出状态 1 node_modules pm ode_modules pm-lifecycleindex.js:301:16)- 没什么特别的
Exit status 1 node_modules pm ode_modules pm-lifecycleindex.js:301:16) - nothing specific
我试过了:
"start": "npm run electron . && cross-env BROWSER=none react-scripts start",
,但这会启动 Electron,当我关闭它时,它会启动 React 应用程序.
, but this starts the Electron, when I close it, it start the React app.
又报错了:
"electron": "electron .",
"start": "cross-env BROWSER=none react-scripts start",
"both": ""npm run electron" "npm run start"",
我不知道,如何只用一个 NPM 命令启动 react-create-app
和 Electron
?
I don't know, how to start react-create-app
and Electron
with just one NPM command ?
推荐答案
考虑使用 concurrent.
cd
到您的项目目录并运行以下命令进行安装:
cd
to your project directory and run the following command to install it:
npm i -D concurrently
然后在 package.json 的 scripts
部分重新定义 both
脚本,如下所示:
Then redefine the both
script in the scripts
section of your package.json as follows:
"both": "concurrently "npm start" "npm run electron""
或稍微缩短的等价物:
"both": "concurrently "npm:start" "npm:electron""
这篇关于使用一个 NPM 命令启动 react-create-app 和 Electron.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!