代码之家  ›  专栏  ›  技术社区  ›  zac

如何在package.json中添加额外的start子句命令?

  •  0
  • zac  · 技术社区  · 5 年前

    我有我的包.json是这样开始的

    "scripts": {
        "start": "react-scripts start",
    

    如何添加?json server db.json?启动?

    2 回复  |  直到 5 年前
        1
  •  1
  •   frandroid    5 年前

    您可以使用 npm-run-all 能够运行多个任务的模块。

    "scripts": {
        "start": "run-s rscript jserver",
        "rscript": "react-scripts start",
        "jserver": "json-server db.json"
    }
    
        2
  •  0
  •   Jackkobec    5 年前

    另一个同时使用的解决方案( https://www.npmjs.com/package/concurrently )

    npm install concurrently --save
    
    "scripts": {
        "start": "concurrently \"npm run server\" \"react-scripts start\"",
        "server": "nodemon server/app",
        "build": "react-scripts build",
    ...
    
        3
  •  0
  •   ravibagul91    5 年前

    你可以这么做,

    "scripts": {
        "start": "react-scripts start && json-server --watch db.json",
    }
    

    注: 您必须安装 json-server 全球性的 npm install -g json-server . 同时确保 db.json 文件没有任何错误/拼写错误,因为 JSON服务器 它编译了 数据库JSON 如果输入错误, 数据库JSON 文件显示错误

    Error Showing: ERR! code ELIFECYCLE
    Error Showing: ERR! errno 1
    
        4
  •  0
  •   zac    5 年前

    这种组合对我很管用。我不得不选择另一个端口+并行运行。

    "start": "run-p jserver rscript",
        "rscript": "react-scripts start",
        "jserver": "json-server db.json --port 3004",