使用一个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 electronic
启动Electron并使用- npm start
进行React.
and I can start Electron with npm run electron
and React with - npm start
.
我想要的只是用一个命令来启动React和Electron,例如: npm都运行
.
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 \ npm \ node_modules \ npm-lifecycle \ index.js:301:16)-没有具体内容
Exit status 1 node_modules\npm\node_modules\npm-lifecycle\index.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 ?
推荐答案
-
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屋!