lib/ and import it by name.
Rules
- A folder under
lib/is a library when it containslib.ts,lib.tsx,lib.jsorlib.jsx. - Its name is whatever that file exports as
libId. Without one, the folder name is used, solib/helpers/lib.tsisimport x from 'helpers'. libIdis 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.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.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.