当前位置:网站首页>npm link的简单介绍及使用
npm link的简单介绍及使用
2022-07-26 02:18:00 【闲鱼_JavaScript】
简单介绍
- 这对于安装你自己写的东西很方便,这样你就可以在它上面工作和迭代测试,而不必不断地重建。
- 上面白话文就是:你自己写了个npm模块,想要测试,可以使用npm link到全局,然后其他地方引用测试
使用
- 你封装好了的模块(项目名称为: myModules,项目路径:d:\xxxxxx\xxxxx\x\myModules)你即去测试的地方(项目名称为 test,项目路径为:d:\test);温馨提示:项目名称为 package.json 中的 name;
- 在 myModules 项目下进入cmd小黑框,然后输入 npm link;(注意:此处不需要在后面接任何名字)
npm link
- 然后去到 test 项目进入cmd小黑框输入 npm link myModules;(注意:此处需添加你即将连接的模块名字,也就是你模块中 package.json 中的name字段)
npm link myModules
- 当你成功的时候会有提示(连接地址指向提示)
- 问题1:如果出现去 npm 地址或者你私服地址去查找的时候则说明你写的模块名字不对!请复制粘贴你的名字,再不然就是你挂载的地方不是你模块的根目录(npm link 需要在你根目录运行)
- 测试: 如果只是一个方法的话,建议直接node index.js;(node 运行测试)(注意:此方法得 commonjs规范【暴露:module、module.exports,引入:require(‘文件地址或模块名字’)】)
- 测试完毕了后,需要取消link,测试项目输入npm unlink myModules 取消对应的模块;myModules项目则输入 npm unlink 取消全局的模块挂载;
// 测试项目取消挂载
npm unlink myModules
// myModules项目取消挂载
npm unlink
示例代码
package.js 中 main 字段为指向地址,请配置到指向你的模块地址;(myModules/package.json)
{
"name": "myModules",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
模块主体内容(myModules/src/index.js)
const myModules = res => res
module.exports = myModules
引用(test/index.js)
const myModules = require('myModules')
const data = require('./data.js')
console.log(myModules(new Uint8Array(data)), 'test')
边栏推荐
- scipy.sparse.vstack
- 2022-07-17
- A MCU event driven C framework
- [pyqt5 packaged as exe]
- [2021] [paper notes] 6G technology vision - otfs modulation technology
- MySQL(4)
- 微信小程序解密并拆包获取源码教程
- 18_ Request file
- 【2020】【论文笔记】磁控溅射法生长Bi2Te3/CoFeB双层异质结——
- Prometheus + process exporter + grafana monitor the resource usage of the process
猜你喜欢

Prometheus+blackbox exporter+grafana monitoring server port and URL address

Ti am335x industrial control module uses the Debian system of beaglebone (BBB)

prometheus+redis-exporter+grafana 监控redis服务

TCP three handshakes and four waves

Illustration of the insertion process of b+ tree

i. Mx6ull snvs power domain GPIO status hold verification

What does the Red Cross in the SQL editor mean (toad and waterdrop have been encountered...)

C unit test

商业智能BI全解析,探寻BI本质与发展趋势
![Web3.0 blog DAPP development practice [2022]](/img/18/f386246ff6ffbd0a42df57c3cd9170.png)
Web3.0 blog DAPP development practice [2022]
随机推荐
Worthington papain - production of glycopeptides from purified proteoglycans (attached Literature)
1205 Lock wait timeout exceeded; Try restarting transaction processing
I.MX6UL核心模块使用连载-触摸屏校准 (九)
I.MX6UL核心模块使用连载-以太网测试 (七)
AttributeError: ‘Document‘ object has no attribute ‘pageCount‘
BigDecimal use
numpy.sort
[red team] att & CK - using bits services to achieve persistence
转:高效做正确的事
prometheus+process-exporter+grafana 监控进程的资源使用
[2019] [paper notes] tunable THz broadband absorption based on metamaterials——
A pluggable am335x industrial control module onboard WiFi module
Sqlyog data import and export graphic tutorial
SQL how to return all data when the input query condition is empty
i.MX6ULL SNVS电源域GPIO状态保持验证
A MCU event driven C framework
Activiti workflow gateway
Worthington nuclease and Micrococcus related research and determination scheme
还在用==0 null equal 判断空值吗,对isEmpty 和 isBlank有多少了解呢
租户问题。