繁体   English   中英

如何在没有“run”的情况下运行“npm command”(即“npm command”而不是“npm run command”)?

[英]How to run “npm command” run without “run” (i.e. “npm command” instead of “npm run command”)?

我的package.json定义:

    ...
    "scripts": {
        "start": "node scripts/start.js",
        "build": "node scripts/build.js",
        "test": "node scripts/test.js",
        "debug": "node --inspect-brk=9229 scripts/start.js"
    },
    ...

npm startnpm test分别作为npm run startnpm run test 但是, npm build没有:

$ npm build
npm WARN build `npm build` called with no arguments. Did you mean to `npm run-script build`?

我需要在npmbuild之间放置run ,即npm run build

npm debug也是如此,尽管 output 不同于 ZBB30E85411B56DC8AB44 中的npm build

$ npm debug

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, 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

当然,这似乎是因为starttest都属于where <command> is one of: list。

But I was wondering, is there a way to tell npm to run an arbitrary command like npm build or npm debug or even npm my_command just using just npm build / npm debug / npm my_command ?

这只是我的好奇心,这就是我问的原因。

感谢您的关注。

我很抱歉,但直接不可能:(

我想,您可以克隆npm 存储并添加您自己的脚本

之后你就可以像npm my_awesome_command一样启动它

您可以改用纱线。 全局安装纱线..(在 linux 或 Mac 中)

sudo npm i -g yarn

那你可以试试。。

yarn start

看看它是否有效..在我的反应应用程序中它工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM