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

后端 未结 4 1712
忘掉有多难
忘掉有多难 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 11:07

    NPM in 2019

    npm build no longer exists. You must call npm run build now. More info below.

    TLDR;

    npm install: installs dependencies, then calls the install from the package.json scripts field.

    npm run build: runs the build field from the package.json scripts field.


    NPM Scripts Field

    https://docs.npmjs.com/misc/scripts

    There are many things you can put into the npm package.json scripts field. Check out the documentation link above more above the lifecycle of the scripts - most have pre and post hooks that you can run scripts before/after install, publish, uninstall, test, start, stop, shrinkwrap, version.


    To Complicate Things

    • npm install is not the same as npm run install
    • npm install installs package.json dependencies, then runs the package.json scripts.install
      • (Essentially calls npm run install after dependencies are installed.
    • npm run install only runs the package.json scripts.install, it will not install dependencies.
    • npm build used to be a valid command (used to be the same as npm run build) but it no longer is; it is now an internal command. If you run it you'll get: npm WARN build npm build called with no arguments. Did you mean to npm run-script build? You can read more on the documentation: https://docs.npmjs.com/cli/build

    Extra Notes

    There are still two top level commands that will run scripts, they are:

    • npm start which is the same as npm run start
    • npm test ==> npm run test

提交回复
热议问题