imports
Auto-import folders in addition to the defaults, each with the scope of its containing folder, app, shared or server.
imports adds folders whose exports are auto-imported, in addition to the defaults (app/components, app/composables, app/utils, app/stores, app/types, shared/{types,schemas,utils,constants,enums} and server/utils). Each option only accepts folders within its root, and each folder inherits that root's scope, so a server/ service never reaches a component.
serverDirs exists since 1.0; appDirs and sharedDirs since 1.3. Folders are also searched within each layer, with the same relative path.
Usage#
// meeko.config.ts
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({
imports: {
appDirs: ["app/services"],
sharedDirs: ["shared/validators"],
serverDirs: ["server/services", "server/repositories"],
},
});Type#
readonly imports?: {
readonly appDirs?: readonly string[]
readonly sharedDirs?: readonly string[]
readonly serverDirs?: readonly string[]
}Options#
| Option | Type | Default | Description |
|---|---|---|---|
appDirs |
readonly string[] |
[] |
Since 1.3. Folders within app/, with app/ scope: components and .ts files in app/, in the browser and SSR; also server code. Not shared/. |
sharedDirs |
readonly string[] |
[] |
Since 1.3. Folders within shared/, with shared/ scope: the entire project. |
serverDirs |
readonly string[] |
[] |
Folders within server/, only for server code: server/, <script server>, *.route.ts and *.server.ts sidecars. |
Each entry is a relative path starting with its root (app/…, shared/…, server/…), with / or \ and no . or .. segments.
Result#
Each folder is read recursively, in the project and each layer. Its .ts and .mts files contribute exports (excluding *.test.ts, *.spec.ts and *.d.ts); .meeko files in these folders are not components. The .client.ts, .server.ts and .shared.ts suffixes override the folder's scope. Export names are flat: the subfolder is not added to the name, unlike components (App/Card.meeko is AppCard). export function total() in app/utils/cart/total.ts is total, not CartTotal, and two files that export total in a scope are the duplicate name error, even in different folders. A .mts contributes its exports like a .ts. A .cts only works for types: export type works, but a value with export gives TS1287 in meeko check and meeko build and makes the page respond 500 in meeko dev, and export = contributes no name.
- A
typeorinterfaceis brought in withimport type. - A project export with the name of a framework auto-import (
useRoute,useForm…) takes priority. - Two files exporting the same name in one scope produce an error naming both.
- A folder already used for auto-imports or inside another listed folder is not read twice.
meeko checkand the editor declare names in.meeko/types/autoimports/.
Examples#
Server services without imports#
// server/services/orders.ts
export async function markReady(id: string): Promise<{ id: string; status: "ready" }> {
return { id, status: "ready" };
}// server/api/orders/[id]/ready.post.ts: markReady is auto-imported
export default defineApiRoute({ params: orderParams, handler: ({ params }) => markReady(params.id) });Validators shared by the form and API#
// shared/validators/email.ts
export const isCorporateEmail = (value: string): boolean => value.endsWith("@acme.example");isCorporateEmail is available in app/, server/ and shared/ itself.
A server-only service within appDirs#
app/services/cart.ts → app/ (browser and SSR)
app/services/payments.server.ts → server only: a component using it produces MEEK108Common mistakes#
A path outside its root#
export default defineMeekoConfig({ imports: { appDirs: ["services"] } });meeko dev, meeko build, meeko check and meeko routes stop with …/meeko.config.ts: imports.appDirs[0] debe ser una ruta relativa dentro de app/: services; the editor in a trusted workspace marks the entry (MEEK_CONFIG).
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({ imports: { appDirs: ["app/services"] } });Use a serverDirs service in a component#
<!-- app/pages/orders.meeko -->
<script lang="ts">
const orders = await listOrders(); // from server/services
</script>meeko check reports MEEK108: server code cannot reach the browser. Load it in <script server> or expose it through an API.
<script server lang="ts">
export const orders = await listOrders();
</script>imports that is not an object#
export default defineMeekoConfig({ imports: ["server/services"] as never });…/meeko.config.ts: imports debe ser un objeto.
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({ imports: { serverDirs: ["server/services"] } });Notes#
- Scopes and security. Scope prevents a
server/secret from ending up in the browser bundle:serverDirsonly exists in server code. - Development. Creating, editing or deleting a
.tsfile in these folders reloads the registry without restarting; changing theimportslists requires restartingmeeko dev. - Editor. In an untrusted workspace, the editor reads all three lists without executing the configuration if they are literal arrays of strings.