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

后端 未结 4 1713
忘掉有多难
忘掉有多难 2020-12-12 10:35

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

I have noticed in my project that sometimes npm starts failing when np

4条回答
  •  醉话见心
    2020-12-12 10:58

    The main difference is ::

    npm install is a npm cli-command which does the predefined thing i.e, as written by Churro, to install dependencies specified inside package.json

    npm run command-name or npm run-script command-name ( ex. npm run build ) is also a cli-command predefined to run your custom scripts with the name specified in place of "command-name". So, in this case npm run build is a custom script command with the name "build" and will do anything specified inside it (for instance echo 'hello world' given in below example package.json).

    Ponits to note::

    1. One more thing, npm build and npm run build are two different things, npm run build will do custom work written inside package.json and npm build is a pre-defined script (not available to use directly)

    2. You cannot specify some thing inside custom build script (npm run build) script and expect npm build to do the same. Try following thing to verify in your package.json:

      { "name": "demo", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "build":"echo 'hello build'" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": {}, "dependencies": {} }

    and run npm run build and npm build one by one and you will see the difference. For more about commands kindly follow npm documentation.

    Cheers!!

提交回复
热议问题