> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lodemc.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Libraries

> lib/ folders, imported by name instead of a path

Code you use from several places does not need a relative path. Put it in `lib/` and import it by name.

```
MyExpansion/
├── lib/
│   └── greeting-kit/
│       ├── lib.ts          export const libId = 'greeter'
│       └── shout.ts
└── src/
    └── pages/Page.tsx      import greeter from 'greeter'
```

<CodeGroup>
  ```ts lib/greeting-kit/lib.ts theme={null}
  import { shout } from './shout'

  export const libId = 'greeter'

  export function greet(who: string) {
    return shout(`hello ${who}`)
  }

  export default { greet }
  ```

  ```tsx anywhere in the expansion theme={null}
  import greeter from 'greeter'
  import { shout } from 'greeter/shout'
  ```
</CodeGroup>

## Rules

* A folder under `lib/` is a library when it contains `lib.ts`, `lib.tsx`, `lib.js` or `lib.jsx`.
* Its name is whatever that file exports as `libId`. Without one, the folder name is used, so `lib/helpers/lib.ts` is `import x from 'helpers'`.
* `libId` is read from your source without running it, so it must be a plain string literal.
* Names are letters, digits, `_` and `-`.
* Other files in the library are reachable by subpath: `greeter/shout`, `greeter/nested/thing`.
* Two libraries cannot share a name, and a `lib/` folder without an entry file is an error. Both are reported when the expansion loads, naming the folder.

## What they are, and are not

A library is ordinary code in your expansion: same runtime, same permissions, compiled and cached the same way, hot-reloaded with everything else. The only thing that changes is how you import it.

<Note>
  They are per-expansion. Sharing a library **between** expansions is the NMCrate library system, which is not available yet; `dependencies` in `meta.json` must stay empty. The folder shape here is the shape that system will install into, so code written against a local library will move across unchanged.
</Note>

## Editor support

The app writes `.ldstudio/tsconfig.libs.json` with a path mapping per library, and your `tsconfig.json` extends it. Because those are mappings rather than declarations, you get the library's real types, its default export and go-to-definition. Add or rename a library and the file is rewritten the next time the app loads the expansion.
