博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
npm本地包安装_如何在本地测试NPM软件包
阅读量:2508 次
发布时间:2019-05-11

本文共 1477 字,大约阅读时间需要 4 分钟。

npm本地包安装

If you want to develop your own npm package, you first have to test it locally.

如果要开发自己的npm软件包,则首先必须在本地对其进行测试。

I had this need with a project that I wanted to modularize.

我对一个我想模块化的项目有这种需求。

I had a package I called, as an example, flaviocopes-common-database.

我有一个名为flaviocopes-common-database的软件包。

I prepended flaviocopes- to give it a unique namespace.

我在flaviocopes-添加了一个唯一的名称空间。

Inside the package I added a package.json file with the module name in the name property and a few dependencies:

在包内,我添加了一个package.json文件,其模块名在name属性中,并具有一些依赖性:

{  "name": "flaviocopes-common-database",  "version": "1.0.0",  "description": "",  "main": "index.js",  "dependencies": {    "pg": "^8.0.2",    "sequelize": "^5.21.6"  }}

Then I ran

然后我跑了

npm link

This created a symbolic link in the /usr/local/lib/node_modules/ folder, that contains the global npm packages in the system, the ones installed using npm -g, to be clear.

这在/usr/local/lib/node_modules/文件夹中创建了一个符号链接,其中包含系统中的全局npm软件包,这些软件包使用npm -g了安装。

I had

我有

/usr/local/lib/node_modules/flaviocopes-common-database

Pointing to the local file I had in

指向我所在的本地文件

/Users/flavio/dev/code/flaviocopes-common-database

Now in another project I wanted to use this module, so I ran

现在在另一个项目中,我想使用此模块,所以我运行了

npm link flaviocopes-common-database

and I was able to import it in the Node.js code using the usual require() syntax:

并且我能够使用通常的require()语法将其导入到Node.js代码中:

const database = require('flaviocopes-common-database')

翻译自:

npm本地包安装

转载地址:http://kamgb.baihongyu.com/

你可能感兴趣的文章
Nginx配置文件nginx.conf中文详解(总结)
查看>>
Mysql出现Table 'performance_schema.session_status' doesn't exist
查看>>
MySQL innert join、left join、right join等理解
查看>>
sdc时序约束
查看>>
NoC片上网络
查看>>
开源SoC整理
查看>>
【2020-3-21】Mac安装Homebrew慢,解决办法
查看>>
influxdb 命令行输出时间为 yyyy-MM-dd HH:mm:ss(年月日时分秒)的方法
查看>>
已知子网掩码,确定ip地址范围
查看>>
判断时间或者数字是否连续
查看>>
docker-daemon.json各配置详解
查看>>
Docker(一)使用阿里云容器镜像服务
查看>>
Docker(三) 构建镜像
查看>>
FFmpeg 新旧版本编码 API 的区别
查看>>
RecyclerView 源码深入解析——绘制流程、缓存机制、动画等
查看>>
Android 面试题整理总结(一)Java 基础
查看>>
Android 面试题整理总结(二)Java 集合
查看>>
学习笔记_vnpy实战培训day02
查看>>
学习笔记_vnpy实战培训day03
查看>>
VNPY- VnTrader基本使用
查看>>