使用一个 NPM 命令启动 React-create-app 和 Electron.js

gdf*_*dfg 6 node.js npm reactjs electron npm-scripts

我有简单的自定义入门包react-create-appElectron.js. 我已添加到 package.json 文件:

"scripts": {
    "electron": "electron .",
    "start": "cross-env BROWSER=none react-scripts start",
....
Run Code Online (Sandbox Code Playgroud)

我可以用npm run electron- 启动 Electron 并用 React启动npm start

我想要的是只用一个命令来启动 React 和 Electron npm run both

我努力了:

"both": "\"npm start\" \"npm run electron \"", 
Run Code Online (Sandbox Code Playgroud)

但我在日志文件中收到错误:

退出状态 1 node_modules\npm\node_modules\npm-lifecycle\index.js:301:16) - 没有具体内容

我已经尝试过并且:

    "start": "npm run electron . && cross-env BROWSER=none react-scripts start",
Run Code Online (Sandbox Code Playgroud)

,但这会启动 Electron,当我关闭它时,它会启动 React 应用程序。

又报错:

"electron": "electron .",
"start": "cross-env BROWSER=none react-scripts start",
"both": "\"npm run electron\" \"npm run start\"",
Run Code Online (Sandbox Code Playgroud)

我不知道如何启动react-create-appElectron仅使用一个 NPM 命令?

Rob*_*obC 7

考虑同时使用。

  1. cd到您的项目目录并运行以下命令来安装它:

    npm i -D concurrently
    
    Run Code Online (Sandbox Code Playgroud)
  2. 然后bothpackage.jsonscripts部分中重新定义脚本,如下所示:

    "both": "concurrently \"npm start\" \"npm run electron\""
    
    Run Code Online (Sandbox Code Playgroud)

    或稍微缩短的等价物:

    "both": "concurrently \"npm:start\" \"npm:electron\""
    
    Run Code Online (Sandbox Code Playgroud)