HomeAbout

Barrel File

Given the directory structure:

lib |-index.ts |-helpers |-someHelper.ts |-otherHelper.ts |-formatSomething.ts |-getSomething.ts |-index.ts |-service |-someHook.ts |-otherFile.ts

lib/helpers/index.ts would look like this:

// default exports import someHelper from "./someHelper"; import formatSomething from "./formatSomething"; // named exports export * from "./otherHelper"; export * from "./getSomething"; // default exports need to be re-exported export { someHelper, formatSomething, }

lib/index.ts (main export of the library) would look like this:

export * from "./helpers"

Consumers should exclusively import from the main export of the library.

  • Do NOT import from any other file of the library as an external consumer
  • Same pattern as released NPM packages
// do NOT: import { someFunction } from "lib/package/src/nested/directory" // do instead: // external packages: import { someFunction } from "@public-entrypoint" import { someFunction } from "@publicSymbol" // internal packages/libraries: import { someFunction } from "public-interface" import { someFunction } from "library-name"

When using external projects, only use public interfaces.

  • Since you don't have control over the internal structures, do NOT rely on them.
  • Allows for quick pivot when you need to switch away from the external library.
AboutContact