当前位置:网站首页>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')
边栏推荐
- C unit test
- 数仓:银行业数仓的分层架构实践
- SQL manual blind injection and error reporting injection
- LeetCode302场周赛第三题--裁剪数字后查询第 K 小的数字
- What are the functions of cloud notes, and how do browsers add cloud note plug-ins
- 2. Login - verification code function and saving login status
- The third question of leetcode 302 weekly Games -- query the number with the smallest k after cutting the number
- 主键B+ Tree,二级索引B+ Tree及对应的查询过程分析
- 2022-07-17
- SQL how to return all data when the input query condition is empty
猜你喜欢

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...)

Ggplot2 learning summary

How to choose cloud note tool? What can I do with cloud notes?

DialogRPT-Dialog Ranking Pretrained Transformers

1. Mx6ul core module use serialization - view system information (II)

These practical security browser plug-ins improve your efficiency

租户问题。

(Dynamic Programming Series) sword finger offer 48. the longest substring without repeated characters

prometheus+blackbox-exporter+grafana 监控服务器端口及url地址
随机推荐
租户问题。
(CVPR 2019) GSPN: Generative Shape Proposal Network for 3D Instance Segmentation in Point Cloud
AttributeError: ‘Document‘ object has no attribute ‘pageCount‘
Implementation of C iterator
I.MX6UL核心模块使用连载-以太网测试 (七)
商业智能BI全解析,探寻BI本质与发展趋势
MySQL(4)
1. Mx6ul core module serial -iot-6ulx core module brief introduction (I)
Kaggle registration method to solve the problem of man-machine verification
MySQL transaction isolation level
[red team] att & CK - using bits services to achieve persistence
Bitmap这个“内存刺客”你要小心~
【2019】【论文笔记】基于超材料可调谐THz宽频吸收——
How to install opengauss manually (non om mode)
1. Mx6ul core module uses serial EMMC read / write test (IV)
SQL手工盲注、报错注入
Remember a laravel problem script @php artist package:discover handling the post autoload dump event returned with
信息系统项目管理师---第十章沟通管理和干系人管理历年考题
Worthington papain - production of glycopeptides from purified proteoglycans (attached Literature)
1. Mx6ul core module serial Ethernet test (VII)