zoukankan      html  css  js  c++  java
  • [Whole Web] [Node.js] Using npm run to launch local scripts

    npm run allows you to configure scripts inside of your package.json file which can access locally installed node packages. If you're comfortable with this technique, you can also grunt, gulp, or other build tools by customizing your scripts and saving them inside of your package.json file. With this approach, when a developer starts a new project with your package.json, they can simply runnpm install then npm run yourscript without having to install any node packages globally.

    For example:

    If you haven't installed browserify globally, and you use npm to install it locallly:

    npm install browserify --save-dev

    Then you create a test script to run browserify:

      "scripts": {
        "test": "echo "Error: no test specified" && exit 1",
        "demo": "echo Hello World!",
        "b_version": "browserify -v"
      },

    You run on tml:

    npm run b_version

    You will get the version number, but if you type in tml:

    browserify -v

    You will get error, because you haven't installed it globally, which means that I can use npm run to invoke anything I've installed locally without forcing my users to say "npm install -g" to install things globally, Which means with this approach, you could just include a package file in your project, say "npm install" to get everything installed locally, and then npm run whatever task you want to set up, whether it's browserify or whatever. Then it can just grab those locally installed modules and run them.

    More: 

    https://egghead.io/lessons/nodejs-using-npm-run-to-launch-local-scripts#/tab-transcript

  • 相关阅读:
    构建之法阅读笔记05
    构建之法阅读笔记04
    构建之法阅读笔记03
    构建之法阅读笔记02
    构建之法阅读笔记01
    管理系统的简单解析---web
    Java中的异常处理
    多态
    重写与重载
    抽象类与接口
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4339915.html
Copyright © 2011-2022 走看看