[英]How to develop npm module locally
Lets say im working on an app, MyApp, and I want to build an NPM module for it, MyModule. 让我说我正在开发一个应用程序,MyApp,我想为它构建一个NPM模块,MyModule。 Right now I can think of two ways to develop it:
现在我可以想到两种方法来开发它:
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.
例如,我知道在Gemfiles中我只能链接到另一个目录作为路径。 Pretty sure I can't do that with npm tho.
很确定我不能用npm tho做到这一点。
You're looking for the npm link
command , which is a two steps process: 您正在寻找
npm link
命令 ,这是一个两步过程:
npm link
from your MyModule
directory: this will create a global package symlinked to the MyModule
directory npm link
从MyModule
目录:这将创建符号链接到一个全球性的包MyModule
目录 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
). MyApp
目录运行npm link MyModule
:这将在node_modules
创建一个MyModule
文件夹,符号链接到全局符号链接(从而到达MyModule
的实际位置)。 要添加到Paul的答案,您还可以通过在MyApp
目录中执行以下操作来执行上述操作的快捷方式:
npm link ../MyModule
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.