What is the difference between npm install and npm run build?
What is the difference between npm install and npm run build?
回答1
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 is an alias for npm build, and it does nothing unless you specify what "build" does in your package.json file. It lets you perform any necessary building/prep tasks for your project, prior to it being used in another project.
build is called by link and install commands, according to the documentation for build:
This is the plumbing command called by npm link and npm install.
回答2
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 installis not the same asnpm run installnpm installinstallspackage.jsondependencies, then runs thepackage.jsonscripts.install- (Essentially calls
npm run installafter dependencies are installed.
- (Essentially calls
npm run installonly runs thepackage.jsonscripts.install, it will not install dependencies.npm buildused to be a valid command (used to be the same asnpm 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
package.json中有scripts属性,包含了build字段
https://docs.npmjs.com/misc/scripts
"scripts": { "build": "node build/build.js", "analyze": "node build/build.js --report", "dev": "nodemon --watch src -e html,vue,js,scss,css build/build.js" },

浙公网安备 33010602011771号