如何在本地开发 npm 模块 [英] How to develop npm module locally

查看:41
本文介绍了如何在本地开发 npm 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在开发一个应用程序 MyApp,我想为它构建一个 NPM 模块 MyModule.目前我能想到两种开发方式:

Lets say im working on an app, MyApp, and I want to build an NPM module for it, MyModule. Right now I can think of two ways to develop it:

  1. 在 MyApp 中进行更改 -> 保存 -> npm install/path/to/module
  2. 与 1 相同,除了运行 npm install/path/to/module 然后直接在 node_modules 中编辑它然后复制更改.

我想要的是更简单的工作流程.我可以简单地保存文件,刷新页面,我的更改就在那里.那可能吗?例如,我知道在 Gemfiles 中我可以链接到另一个目录作为路径.很确定我不能用 npm tho 做到这一点.

What I'd like is an easier workflow. One where I can simply save the file, refresh the page, and my changes are there. Is that possible? For example, I know in Gemfiles I can just link to another directory as the path. Pretty sure I can't do that with npm tho.

推荐答案

您正在寻找 npm link 命令,这是一个两步过程:

You're looking for the npm link command, which is a two steps process:

  1. 从您的 MyModule 目录运行 npm link:这将创建一个符号链接到 MyModule 目录的全局包
  2. 从您的 MyApp 目录运行 npm link MyModule:这将在 node_modules 中创建一个 MyModule 文件夹,符号链接到全局符号链接(从而到 MyModule 的实际位置).
  1. Run npm link from your MyModule directory: this will create a global package symlinked to the MyModule directory
  2. Run npm link MyModule from your MyApp directory: this will create a MyModule folder in node_modules, symlinked to the global symlink (and thus to the real location of MyModule).

这篇关于如何在本地开发 npm 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆