简体   繁体   English

构建 NPM 包的最佳开发工作流程是什么?

[英]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 的入口点。
  • I am able to include the package in another project by adding "{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 linkhttps://docs.npmjs.com/cli/link )。

Example Usage:示例用法:

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-anode_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.

相关问题 如何在不每次都构建的情况下使用 npm package 进行开发? - How to use a npm package for development without building it every time? 步入NPM包的最佳方法是什么? - What is the best way to step through an NPM Package 字体端NPM软件包文件结构的最佳实践是什么? - What is best practice for font-end NPM package file structure? 在Angular中为开发目的创建虚拟$ resource的最佳方法是什么? - What's the best way to create a dummy $resource for development purposes in Angular? 构建多页响应表单的最佳方法是什么? - What's the best way building a multi-page responsive form? React NPM 包(Dragula)可用于开发但不能用于生产 - React NPM package(Dragula) works in development but not in production 在给定的工作流程中,angularjs和指令的最佳实践是什么? - What is the best practice for angularjs and directives in the given workflow? NPM软件包安装到公共目录中(最佳实践) - NPM package install into public directory (best practice) 在Angular.js应用程序中进行事件驱动开发的最佳实践是什么? - What's the best practice to do event driven development in Angular.js apps? 将开发NPM依赖关系加入到单个元包中 - Joining development NPM dependencies into single meta-package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM