[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
相关文章
- Node.js学习笔记(一)——Node.js概要、NPM与package.json
- js 手动触发input事件
- html js 全局 变量,JS定义全局变量
- node.js常用npm命令
- html如何只刷新页面指定,js控制页面刷新 JS刷新当前页面的几种方法总结
- 【CSS动效实战(纯CSS与JS动效)】02 flex 布局实战(仿 JD 及 gitCode 布局)及 media 自适应初探
- JS设置定时器_js设置定时器
- p5.js 使用npm安装p5.js后如何使用?
- 【源码】PDF.js批注注释插件库(纯JS). 创建和保存PDF批注(PDF 高亮/签名/插图/截屏/文本框/画笔/多边形)-pdf.js
- Node.js v18版本npm run dev 报错opensslErrorStack
- 使用Node.js连接MySQL数据库(node-mysql)
- Linux环境下配置Node.js(linux配置node)
- 快速在Linux平台上安装Node.js(node安装linux)
- 快速掌握JS操作MySQL数据库技巧(js操作mysql数据库)
- node.js与mssql配合实现大批量数据库操作(node mssql批量)
- 利用Node.js封装MSSQL的尝试(node mssql封装)
- 使用JS技术实现Oracle数据库链接(js 链接 oracle)
- 妙用JS获取Oracle信息的快速方法(js获取Oracle)
- js实现网页检测是否安装了FlashPlayer插件
- js以对象为索引的关联数组
- 远离JS灾难css灾难之js私有函数和css选择器作为容器
- js中escape对应的C#解码函数UrlDecode
- js获取坐标通过JS得到当前焦点(鼠标)的坐标属性
- 鼠标焦点离开文本框时验证的js代码
- jquery与js函数冲突的两种解决方法
- 巧用js提交表单轻松解决一个页面有多个提交按钮
- node.js使用npm安装插件时提示installError:ENOENT报错的解决方法
- 我的Node.js学习之路(三)--node.js作用、回调、同步和异步代码以及事件循环
- Node.js安装教程和NPM包管理器使用详解