Sobes.tech
Middle

How did you connect a separate repository with shared components to another project — as a package or otherwise?

sobes.tech AI

Answer from AI

Connecting a separate repository with shared components to another project typically involves several approaches:

  1. Publishing as an npm package — the most common method for frontend. Shared components are packaged into an npm package, which is published to a private or public registry (e.g., npmjs or GitHub Packages). The project then includes it as a regular dependency via package.json.

  2. Git submodule or Git subtree — if you don't want to publish a package, you can include the components repository as a submodule in git. Updates to components are then pulled through git, but this requires additional version management and building.

  3. Monorepo with tools like Lerna or Nx — if projects are in the same repository, you can organize a monorepo where shared components are a separate package, and projects are other packages, all managed centrally.

Example of connecting via an npm package:

// package.json
{
  "dependencies": {
    "common-ui-components": "^1.2.3"
  }
}

After installing with npm install common-ui-components, you can import components:

import { Button } from 'common-ui-components';

This method is convenient for version control, distribution, and reuse of components.

How did you connect a separate repository with shared… - sobes.tech