Skip to content
Meeko
Type to search the guides and the API reference. Open it from any page with / or Ctrl K; move with the arrow keys and open a result with Enter.
Get started

Contents

On this page

alias

Custom path aliases, or changes to ~/, @/, #shared/ and #server/, used in Vite, generated tsconfig files, the editor and @utilities.

configuration Since 1.5.0

Without configuration, Meeko defines four path aliases: ~/ (the project root), @/ (app/), #shared/ (shared/) and #server/ (server/, only in server code). alias adds your own or changes these: each key is a prefix ending in / and each value is a project folder or false to remove the alias.

An alias inherits the scope of its target folder, like auto-imports: an alias pointing to server/ only exists in server code.

Usage#

ts
// meeko.config.ts
import { defineMeekoConfig } from "@meekojs/meeko/framework";

export default defineMeekoConfig({
  alias: {
    "ui/": "app/components/ui/",
    "db/": "server/db/",
    "#server/": false,
  },
});
ts
// a .ts file in app/
import { Button } from "ui/Button";

Type#

MeekoConfig.alias

ts
readonly alias?: Readonly<Record<string, string | false>>

Options#

Value Type Default Description
alias Record<string, string | false> {} (only Meeko's aliases) Prefix → folder relative to the project root (including a layer's folder), or false.
  • Key. Ends in /; no spaces, * or \; does not start with . or /; no //.
  • Value. A relative path inside the project, or false. A nonexistent folder is not an error: the import fails at resolution time.

Result#

Target Where you can use it
Inside server/ Only in server code; in a component or app/, MEEK108.
Inside app/ In app/ and on the server; in shared/, MEEK118.
Another folder (shared/, the root, lib/) Throughout the project.

It applies in Vite (meeko dev, meeko build and all adapters), the tsconfig files Meeko generates (used by meeko check and the editor), the language server and @utilities modules. A custom alias points exactly to its folder; it does not search layers like Meeko's aliases. Changing a Meeko alias ("@/": "src/") makes it a custom alias, with the scope of its new folder.

Examples#

A design folder#

ts
import { defineMeekoConfig } from "@meekojs/meeko/framework";

export default defineMeekoConfig({ alias: { "ui/": "app/components/ui/" } });
meeko
<script lang="ts">
import * as Dialog from "ui/Dialog.meeko";
</script>

Free #shared/ for Node subpath imports#

ts
import { defineMeekoConfig } from "@meekojs/meeko/framework";

// package.json declares "imports": { "#shared/*": "./lib/shared/*.js" }
export default defineMeekoConfig({ alias: { "#shared/": false } });

Without this, Meeko detects the conflict, yields the prefix to package.json and warns once per process.

A project with src/#

ts
import { defineMeekoConfig } from "@meekojs/meeko/framework";

export default defineMeekoConfig({ alias: { "@/": "src/" } });

If tsconfig.json already had "@/*": ["./src/*"], declare it here too: Vite does not read TypeScript paths.

Common mistakes#

A key without a trailing /#

Incorrectts
export default defineMeekoConfig({ alias: { "@ui": "app/components/ui/" } });

meeko dev, meeko build, meeko check and meeko routes stop with …/meeko.config.ts: alias "@ui" debe ser un prefijo que termine en / (como "@/", "~/" o "lib/"), sin espacios, * ni \, y que no empiece por . ni /.

Correctts
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({ alias: { "@ui/": "app/components/ui/" } });

A folder outside the project#

Incorrectts
export default defineMeekoConfig({ alias: { "ui/": "../design-system/src/" } });

…/meeko.config.ts: alias "ui/" debe ser una ruta relativa dentro del proyecto (su carpeta o la de un layer): ../design-system/src/. For code from another repository, install it as a package.

Correctts
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({ alias: { "ui/": "layers/design/app/components/" } });

A server alias in a component#

Incorrectmeeko
<script lang="ts">
import { db } from "db/client"; // "db/": "server/db/"
</script>

meeko check, the editor and the browser build report MEEK108, even with import type. For a server type, use ~/server/….

Correctmeeko
<script server lang="ts">
import { db } from "db/client";
export const total = await db.orders.count();
</script>

Notes#

  • meeko.config.ts. Node loads the configuration without Vite: neither it nor its imported modules can use aliases.
  • Editor. In an untrusted workspace, the editor reads alias without executing the configuration only if it is an object literal containing strings and false; otherwise, it uses the default aliases.
  • Priority. A paths pattern in tsconfig.json or a Vite resolve.alias covering a Meeko prefix disables it, with a warning; a #… entry in package.json imports also wins.
  • Packages. Modules in node_modules never receive project aliases.

Was this page helpful?

Add a comment

It is sent when you choose “Yes” or “No”. Only the page, your answer and the comment are stored: no cookies and no personal data.

0 of 2000 characters

Edit on GitHub: docs/en/reference/config/config-alias.md