Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between `npm run-script build` vs `npm build`?

Tags:

node.js

npm

When I run npm build, it gives this error:

npm WARN build `npm build` called with no arguments

So, what's the difference between npm run-script build and npm build?

like image 793
Elangovan Avatar asked Apr 02 '18 05:04

Elangovan


People also ask

What is the difference between ng build and npm run build?

ionic build uses ng build internally. If you run ng build directly, Ionic hooks won't be triggered as it is bypassed. npm run build picks the "build" from package. json which is the same as ng build .

What does npm Run script build?

foreground-scripts Run all build scripts (ie, preinstall , install , and postinstall ) scripts for installed packages in the foreground process, sharing standard input, output, and error with the main npm process.

What is the difference between npm start and npm run build?

npm install installs dependencies into the node_modules/ directory, for the node project you're working on. You can call install on another node. js project (module), to install it as a dependency for your project. npm run build does nothing unless you specify what "build" does in your package.

What is the difference between npm run dev and npm run serve?

npm run serve is basically asking the package manager (npm) to run the command specified under the name serve in the package. json file. The same goes for the npm run dev command. It is possible that both execute the same command or different things.


2 Answers

npm run-script is a way to execute arbitrary commands specific to the project/package. Check your applicable package.json file, which will have defined what happens when you execute npm run-script build for that package. It may also include what happens when you run common commands, such as npm run-script test.

As you can see in the documentation for npm run-script, this arbitrary command can include arguments, which you need to refer to your package.json to learn more about.

npm build is not a unique command to the package, and is a native command that ships with npm, as you can see in its documentation.

like image 67
IlIIlllIIIlIIlllIlIllIIIlIlI Avatar answered Oct 04 '22 03:10

IlIIlllIIIlIIlllIlIllIIIlIlI


The best answer is in this SO article.

Basically...

npm run == npm run-script

Plus, certain common tasks are aliased so that the following are true...

npm test == npm run-script test

npm build == npm run-script build

For common tasks, use...

npm start

npm build

npm test

npm restart

And for all others, use...

npm run <my-task>

like image 37
Jeremy Foster Avatar answered Oct 04 '22 02:10

Jeremy Foster