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

查看:79
本文介绍了如何在本地开发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. 进行更改 - >保存 - > npm install / path / to / module in MyApp

  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. 运行 npm链接MyModule MyApp 目录的code>:这将在 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天全站免登陆