-1

Is there a way to run npm scripts that have only been installed using --save-dev using the terminal? Currently, I add a script to the scripts section within the package.json and then run npm run myscriptname. This works, but is there a more direct way without the entry in package.json?

EDIT:

In my example I use lerna to multiple packaging. To initialize the lerna repository the following steps are necessary:

mkdir LernaProject
cd LernaProject
git init
npm init
npm install lerna --save-dev

Now I want to run lerna init, but I don't know how or if it is possible to run that directly due to my local install with --save-dev and not with -g. Hence, I add an entry in the package.json:

{
  ...
  "scripts": {
    "lerna:init": "lerna init"
  }
  ...
}

And then I run that entry:

npm run lerna:init
Socrates
  • 8,724
  • 25
  • 66
  • 113

2 Answers2

1

Luckily found it out myself, read from here.

npm run env lerna init

This though does not work on Windows. Only tested on Linux. Probably also works on a Mac.


Another way to do the same is to use npx as mentioned here.

npx lerna init
Socrates
  • 8,724
  • 25
  • 66
  • 113
0

if you create package.json(npm init is easiest way) and then install dependecies they will be saved in package.json.If you want install all dependecies from package.json you can run npm install. You need define scripts so you can run them.

Mladen Skrbic
  • 154
  • 2
  • 12