zoukankan      html  css  js  c++  java
  • 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 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

    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"
      },
  • 相关阅读:
    python中的内置函数的思维导图
    练习(面试题):关于生成器函数的求和问题
    推导式, 生成器表达式
    生成器
    静态代码块
    java中内存的划分
    静态方法
    Chapter07Scanner类、Random类、ArrayList类
    泛型
    对象数组
  • 原文地址:https://www.cnblogs.com/chucklu/p/12911492.html
Copyright © 2011-2022 走看看