6

I want to split my web project into three: front-end, back-end and super-admin.

What is the best way to re-use the components across code bases? Npm packages? That seems hard to maintain:

  1. Open component dev package
  2. Make changes
  3. Push changes
  4. Tag version
  5. Update all projects

Seems complex and prone to errors. Is there a better way?

1
  • What is your ideal scenario when updating a component that's being used across multiple projects? Opposed to updating (or deciding to leave unchanged) the dependency version. Commented Mar 17, 2016 at 22:57

1 Answer 1

6

Depends on if you need to use different versions of the shared components from different projects. If so, you probably need to make a versioned npm package. However, if you just want to share the packages and use the same version everywhere, you have other options. For one, you don't have to actually build and publish an npm packge, you can just use npm link. This will basically create a symlink to your shared code in node_modules of the other projects.

Alternatively, you can do it without any npm package at all, just have the shared components in a separate project (directory) and import them in javascript through an alias, using a bundling system (webpack alias / browserify aliasify).

Sign up to request clarification or add additional context in comments.

1 Comment

FYI, Importing React components in javascript through an alias from a different directory (with a separate node_modules dependency tree) results in multiple React versions and will create errors in usage. You will likely see this: "Uncaught Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's render method, or you have multiple copies of React loaded."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.