[英]What's the best development workflow for building an NPM package?
I am currently trying to package a javascript library.我目前正在尝试打包一个 javascript 库。 So far I have the package set up as follows:
到目前为止,我的包设置如下:
npm build
puts everything in a build
directory npm build
将所有内容放在build
目录中main
attribute in package.json
points to the entrypoint in build
that exports my libary's top-level API. package.json
main
属性指向build
中导出我的库的顶级 API 的入口点。"{packagename}": "file:{pathToMyPackage}"
"{packagename}": "file:{pathToMyPackage}"
将包包含在另一个项目中My question is this: I am now trying to troubleshoot my package from the other project.我的问题是:我现在正在尝试从另一个项目中排除我的包的故障。 Each time I make changes, I must rebuild the project to reflect the changes AND I must
rm -rf node_modules/{packagename} && npm install
on the project that is using the local package.每次进行更改时,我都必须重建项目以反映更改,并且我必须在使用本地包的项目上执行
rm -rf node_modules/{packagename} && npm install
。
I know I can add some kind of watcher to the package that will build when new files are saved, but how can I make the higher-level project monitor changes to the local package it is using?我知道我可以向包添加某种监视程序,以便在保存新文件时构建,但是如何对它正在使用的本地包进行更高级别的项目监视器更改? Is there a magic tool for this sort of thing, or do people just add custom npm scripts while they are doing development on a dependency?
是否有针对此类事情的神奇工具,或者人们是否只是在对依赖项进行开发时添加自定义 npm 脚本?
Thanks!谢谢!
What you're looking for is npm link
( https://docs.npmjs.com/cli/link ).您正在寻找的是
npm link
( https://docs.npmjs.com/cli/link )。
package-a
depends on package-b
. package-a
依赖于package-b
。
Navigate to package-b
's project folder on the command line.在命令行上导航到
package-b
的项目文件夹。 Run npm link
.运行
npm link
。
Now navigate to package-a
's folder and run npm link package-b
(You may need to run npm uninstall package-b
first; not sure).现在导航到
package-a
的文件夹并运行npm link package-b
(您可能需要先运行npm uninstall package-b
;不确定)。
This will create a symlink in package-a/node_modules/package-b
to package-b
's working directory.这将在
package-a/node_modules/package-b
创建一个指向package-b
工作目录的符号链接。 Any changes you make there will be reflected in the node_modules
for package-a
.您在那里所做的任何更改都将反映在
package-a
的node_modules
中。
Just keep this in mind;请记住这一点; if you break something while working on
package-b
, package-a
may break too.如果您在处理
package-b
弄坏了某些东西,那么package-a
也可能会损坏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.