簡體   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