[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
相关文章
- js中实现多态
- 【nodejs原理&源码赏析(6)】深度剖析cluster模块源码与node.js多进程(下)
- [Typescript] Convert a js project to typescript
- [Whole Web] [Node.js] Using npm run to launch local scripts
- [Node.js] Configuring npm package.json scripts
- [Node.js] CommonJS Modules
- jquery ajax分页 js对象
- [Node.js] npm init && npm install
- SAP UI5应用在SAP WebIDE里clone之后出现404 not found error for sap-ui-core.js错误的原因分析
- 华为OD机试 - 羊、狼、农夫过河(Java & JS & Python)
- 华为OD机试 - 分苹果(Java & JS & Python)
- js随机飘动的广告图片代码demo效果示例(整理)
- 14 【node js 6/7】
- js 依据“;”折行
- Node.js:使用nrm来管理npm源
- Appium基础 — 补充:Node.js介绍