7

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'
vsync
  • 118,978
  • 58
  • 307
  • 400
javad bat
  • 4,236
  • 6
  • 26
  • 44
  • 1
    I see you accept an answer. Could you share your solution? – Matt. Jun 10 '21 at 03:45
  • best solution is to provide config from outside of your module file when you want to use it, so you can provide it as a function argument or global variable. but if you need default config in your case you can put it in ignore list of npm or git – javad bat Nov 21 '22 at 10:53

1 Answers1

1

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.

minitauros
  • 1,920
  • 18
  • 20
  • 1
    Could you further expand on this? I'm not quite following and have the same project requirement as OP. – Matt. Jun 10 '21 at 03:44
  • Re-reading OP's question I think what would work is to create an NPM package with different configs. That NPM package can then be imported (with all its different configs). In my answer I tried to mention that usually production configs don't get included in the NPM package, and that that package should only include default, publicly visible configuration. – minitauros Jun 10 '21 at 09:56
  • 1
    But how do you reference it ? How do you get any data from it, inside your application ? – Wings Nov 17 '22 at 23:27