-
-
Notifications
You must be signed in to change notification settings - Fork 106
Description
Problem
intlayer currently exposes build-time and development tooling through the same entrypoints used at runtime.
Because of this, importing very small features pulls large parts of the ecosystem into the dependency graph.
Examples observed in a Next.js production project:
| Import | Added to graph |
|---|---|
import type { IntlayerConfig } from "intlayer" |
~111 KB (≈39 KB gz) |
import { withIntlayer } from "next-intlayer/server" |
~1.6 MB gz |
The reason is architectural rather than optimization:
- The main
intlayerpackage depends on CLI/config/compiler modules - The Next.js helper (
withIntlayer) also performs build/watch responsibilities - Dev tooling (watchers, generators, filesystem loaders) becomes reachable from runtime entrypoints
- Bundlers and analyzers cannot reliably tree-shake these paths
Even if some code executes only in Node, exposing it through runtime entrypoints:
- inflates dependency graphs
- increases install/build time
- risks accidental bundling in edge/serverless environments
- makes performance analysis confusing
Root Cause
There is no strict separation between:
| Layer | Should be |
|---|---|
| Runtime (browser/server execution) | minimal, stable |
| Server helpers | node-only |
| Build/dev tooling | isolated |
| CLI | isolated |
Currently these responsibilities are mixed across intlayer and next-intlayer/server.
Proposed Solution
Introduce explicit entrypoint separation:
intlayer/
runtime → minimal resolver & types only
react → hooks only
server → server utilities (no watchers)
dev → generators & watchers
cli → commands
next-intlayer/
plugin → thin Next.js config wrapper
server → runtime helpers
dev → build/watch integration
Additionally:
Lazy-load dev tools
if (process.env.NODE_ENV !== "production") {
await import("@intlayer/chokidar");
}Expected Result
| Area | Current | After separation |
|---|---|---|
| Runtime imports | tens of KB | single-digit KB |
| Next plugin graph | ~1.6MB gz | small (<50KB expected) |
| Tree-shaking | unreliable | reliable |
| Edge compatibility | risky | safe |
Why This Matters
i18n libraries are imported everywhere in an app.
Any overhead multiplies across the entire project.
Separating runtime from tooling would:
- reduce bundle size significantly
- improve install/build performance
- simplify dependency graphs
- improve edge/serverless compatibility
If useful, I can help test a runtime-only build and provide bundle analysis feedback.