simondefreeze
simondefreeze

Reputation: 189

Creating npm package for site which uses redux

I have written a create-react app which has a dependency on Redux. I would like to package up my app in an NPM package so I can use it in another site that I am building which also uses redux.

I was wondering if it is possible to package up my app provided that it has a dependency on Redux?

Upvotes: 3

Views: 2444

Answers (1)

sarneeh
sarneeh

Reputation: 1388

Sure you can! But there are some caveats in this approach:

  1. You will need to synchronise the versions of React/Redux in both packages because it would be really bad to have multiple versions of these libraries on your website (performance).
  2. If you'd like transfer data between those two apps you'd have to expose some kind of API which will allow to do that (because both apps will work on separate Redux instances.

If you want to make modular apps you could go another way:

  1. Create an React/Redux app but don't make it setup Redux itself - just expose the reducer.
  2. Anywhere you'd like to use the created app - just import the reducer and plug it in in your Redux instance.

This approach will be a lot lighter for the user :)

Upvotes: 6

Related Questions