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

  • 相关阅读:
    2021年欺骗式防御技术将迎来爆发
    可以简化决策过程的10个大数据源
    “AI+”改变世界!不同领域的5大人工智能趋势
    预测2021: 区块链领域新景观
    后量子时代的密码学
    考试
    进度总结8
    进度总结7
    进度总结6
    进度总结5
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4339915.html
Copyright © 2011-2022 走看看