简体   繁体   English

如何使可配置 npm package

[英]How to make configurable npm package

We have many projects and we want to share our component between them but the problem is each project have their special config file that indicates the server URLs or custom error handler module and etc.我们有很多项目,我们想在它们之间共享我们的组件,但问题是每个项目都有自己的特殊配置文件,用于指示服务器 URL 或自定义错误处理程序模块等。

My question is, how to publish a package in npm or any other way, in a way that we can import different config file in our component on a different project.我的问题是,如何在 npm 或任何其他方式中发布 package,以便我们可以在不同项目的组件中导入不同的配置文件。

For more information, we've tried bit platform but it raises an error too, on a code line we import the config file有关更多信息,我们尝试了bit platform 但它也引发了错误,在代码行上我们导入了配置文件

import config from './modules/general-config'

Usually you exclude the config files from your repository (by ignorning them in your.gitignore) and provide a .dist config (the standard config that comes with the distribution, which has some default/example values that you can copy to your own, local config).通常你从你的存储库中排除配置文件(通过在你的.gitignore中忽略它们)并提供一个.dist配置(发行版附带的标准配置,它有一些默认/示例值,你可以将它们复制到你自己的,本地的配置)。

Submit your package to NPM after you've created an account there, and I guess it should work.在那里创建帐户后,将您的 package 提交到 NPM,我想它应该可以工作。 For more info, see https://docs.npmjs.com/getting-started/creating-node-modules .有关详细信息,请参阅https://docs.npmjs.com/getting-started/creating-node-modules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM