简体   繁体   中英

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

my package.json defines:

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

Both npm start and npm test work as npm run start and npm run test respectively. However, npm build doesn't:

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

I need to put run between npm and build , ie npm run build .

The same goes for npm debug , though the output is different than the output from 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

Of course, it seems to be because start and test both fall into the 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 ?

It's just my curiosity, that's why I am asking.

Thank you for your attention.

I'm so sorry, but it's impossible directly:(

I suppose, You can clone the npm repo and add your own script .

And after it You will be able to launch it like npm my_awesome_command

You can use yarn instead. To install yarn globally..(In linux or Mac)

sudo npm i -g yarn

Then you can try..

yarn start

See if it works.. In my react app it works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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