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

是否可以在中创建自定义npm start命令包.json在节点.js

  •  -2
  • helpME1986  · 技术社区  · 8 年前

    我想实现在npm中同时运行两个命令的情况:

    npm start
    npm startDev
    

    {
      "name": "Test",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "SET NODE_ENV=production & nodemon servis.js",
        "startdev": "nodemon servis.js"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "dependencies": {
        "express": "^4.16.3",
        "morgan": "^1.9.0",
        "nodemon": "^1.18.3"
      }
    }
    

    跑步 npm启动 npm开始日期 我明白了

    Usage: npm <command>
    where <command> is one of:
        access, adduser, bin, bugs, c, cache, completion, config,
        ddp, dedupe, deprecate, dist-tag, docs, doctor, edit,
        explore, get, help, help-search, i, init, install,
        install-test, it, link, list, ln, login, logout, ls,
        outdated, owner, pack, ping, prefix, profile, prune,
        publish, rb, rebuild, repo, restart, root, run, run-script,
        s, se, search, set, shrinkwrap, star, stars, start, stop, t,
        team, test, token, tst, un, uninstall, unpublish, unstar,
        up, update, v, version, view, whoami
    
    1 回复  |  直到 8 年前
        1
  •  4
  •   Orelsanpls    8 年前

    有一堆 preset 命令,例如 start 在文件中定义为:

    它运行包的“start”中指定的任意命令 其“scripts”对象的属性。如果未指定“开始”属性 在“scripts”对象上,它将运行node服务器.js.


    如果要添加不是 ,就像 startDev package.json ,就像你做的那样:

    {
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "SET NODE_ENV=production & nodemon servis.js",
        "startdev": "nodemon servis.js"
      },
    }
    

    但要运行它,你必须使用 npm run

    这将从包的“scripts”对象运行任意命令。如果 没有提供“命令”,它将列出可用的脚本。 run[-script]由test、start、restart和stop命令使用, 但也可以直接调用。当包中的脚本 重启)并直接运行脚本。


    例子

    npm run startdev
    
    推荐文章