Search code examples
javascriptnpmecma

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.

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.

For more information, we've tried bit platform but it raises an error too, on a code line we import the config file

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

Solution

  • 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).

    Submit your package to NPM after you've created an account there, and I guess it should work. For more info, see https://docs.npmjs.com/getting-started/creating-node-modules.