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"
      },
  • 相关阅读:
    C#调用WebService实现天气预报
    火狐完整版下载地址
    Unity3D 中 2D_Toolkit插件下载 和 导入方法
    给大家分享个 网站头像上传的 插件
    JQuery工具方法,实例方法
    ireport5.6.0 win10打不开
    JFreeChart 零散
    JS 类继承 原型继承
    技术电子书下载网址
    正则 变量替换
  • 原文地址:https://www.cnblogs.com/chucklu/p/12911492.html
Copyright © 2011-2022 走看看