# Build-time packages

Each team publishes its feature as a versioned npm package. The shell installs those packages, builds once, and ships a single bundle.

## How it works

1. **Teams publish packages.** Team A and Team B each release a versioned package to a registry.
2. **The shell installs them.** The shell raises the package versions in its package.json and installs them.
3. **One build, one bundle.** A single build compiles every team's code and the shared dependencies into one bundle. Shared libraries are included once, as long as every package accepts the same version.
4. **One release.** The bundle ships. Any team's change goes through steps 2 to 4 again.

## Pros

- Simplest model and tooling: packages and one ordinary build.
- One build, so shared dependencies are deduplicated when the packages agree on versions.
- Teams import each other's code with normal, type-checked imports.

## Cons

- Every change needs the shell to rebuild and release.
- Releases happen in lockstep: teams wait on one release train.
- Package versions can drift between teams.

## Best when

- A few teams that are fine with a shared release.
- Performance-critical pages where one optimized bundle matters.
- Sharing a component library or design system.

## Avoid when

- Teams must deploy on their own schedule.
- Several frameworks need to live in one product.
- One team needs to ship fixes many times a day.

## In code

`shell/package.json · shell/src/App.jsx`

```jsx
// shell/package.json (excerpt)
{
  "dependencies": {
    "@shop/team-a": "^1.4.0",
    "@shop/team-b": "^2.0.0"
  }
}

// shell/src/App.jsx
import { Search } from "@shop/team-a";
import { Cart } from "@shop/team-b";
```

## Ratings

_Editorial judgement for a typical team, from 1 to 5._

- **Team independence: 2/5** (higher is better). Teams publish packages on their own, but nothing reaches users until the shell rebuilds and releases.
- **Runtime performance: 5/5** (higher is better). One build produces one bundle, with shared dependencies deduplicated when the packages accept the same versions.
- **Complexity: 1/5** (lower is simpler). Only packages and a normal build; there is no runtime loader to run.
- **SSR / SEO support: 5/5** (higher is better). The result is one ordinary app, so any server rendering setup works as usual.
- **Tech-agnostic: 1/5** (higher is better). Packages are compiled into the shell, so they share its framework and version.
- **Isolation: 1/5** (higher is better). All code runs in one bundle and one page, so styles, globals and errors are shared.
- **UX consistency: 5/5** (higher is better). One app with one design system makes a consistent experience the default.
- **Tooling maturity: 5/5** (higher is better). Uses the standard package registry and build tooling every frontend team already has.

## Tooling and ecosystem

There is no special tooling: any package registry (npm, a private registry or a monorepo's workspace packages) and any bundler work. Cam Jackson's article describes this approach and recommends against it for micro frontends, because releases happen in lockstep: a change to one part means recompiling and releasing all of them. It is still a reasonable choice when independent deployment is not what you need.

## Sources

- [Micro Frontends](https://martinfowler.com/articles/micro-frontends.html), Cam Jackson · martinfowler.com

https://microfrontends.dev/approaches/build-time-packages