npm: exec in context?

Viewed 366

I would like to exec what can be executed by scripts in npm.

For example I have a vue-press installed and I would like to exec vuepress eject. In my scripts I can see vuepress is accessible, but I don't have a script for eject:

  "scripts": {
    "dev": "vuepress dev docs",
    "build": "vuepress build docs"
  },
  "license": "MIT",
  "devDependencies": {
    "vuepress": "^1.3.1",
    "@vuepress/plugin-back-to-top": "^1.3.1",
    "@vuepress/plugin-medium-zoom": "^1.3.1"
  }

So I could create a script for one use or use whatever command npm exec. I am looking for the latter solution.

1 Answers

In the docs it states the following about executables:

Note: Bold emphasis added by me.

When in global mode, executables are linked into {prefix}/bin on Unix, or directly into {prefix} on Windows.

When in local mode, executables are linked into ./node_modules/.bin so that they can be made available to scripts run through npm. (For example, so that a test runner will be in the path when you run npm test.)

So, given your requirement you can:

  1. cd to your project directory.

  2. Then run the following command:

    ./node_modules/.bin/vuepress eject
    
Related