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 install
is not the same asnpm run install
npm install
installspackage.json
dependencies, then runs thepackage.json
scripts.install
- (Essentially calls
npm run install
after dependencies are installed.
- (Essentially calls
npm run install
only runs thepackage.json
scripts.install
, it will not install dependencies.npm build
used 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" },
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2018-05-18 innerxml and outerxml
2017-05-18 查看以及改变文件的编码格式
2017-05-18 difference in physical path, root path, virutal path, relative virtual path, application path and aboslute path?
2017-05-18 Anatomy of an IIS7 configuration path
2017-05-18 Understanding IIS Bindings, Websites, Virtual Directories, and lastly Application Pools
2017-05-18 netsh http的使用
2016-05-18 string[][]和string[,] 以及 int[][]和int[,]