本文介绍了如何在本地开发 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:
- 在 MyApp 中进行更改 -> 保存 -> npm install/path/to/module
- 与 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:
- 从您的
MyModule
目录运行npm link
:这将创建一个符号链接到MyModule
目录的全局包 - 从您的
MyApp
目录运行npm link MyModule
:这将在node_modules
中创建一个MyModule
文件夹,符号链接到全局符号链接(从而到MyModule
的实际位置).
- Run
npm link
from yourMyModule
directory: this will create a global package symlinked to theMyModule
directory - Run
npm link MyModule
from yourMyApp
directory: this will create aMyModule
folder innode_modules
, symlinked to the global symlink (and thus to the real location ofMyModule
).
这篇关于如何在本地开发 npm 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!