Skip to content

Function: xmAliases()

API / @xmachines/shared / vite-aliases / xmAliases

function xmAliases(importMetaUrl, target?): Record<string, string>;

Defined in: vite-aliases.ts:292

Vite resolve.alias entries for all @xmachines/* workspace packages.

Maps every package to its TypeScript source entry so that pnpm run dev works without a prior pnpm run build. Required because pnpm run clean removes all dist/ directories — including transitive dependencies — leaving Vite unable to resolve package.json exports that point to dist/.

The map is derived from the workspace layout at config-load time (see buildAliases), so adding a new package needs no edit here. A few special-case subpath aliases are maintained explicitly on top.

Usage in a demo vite.config.ts:

import { xmAliases } from “@xmachines/shared/vite-aliases”;

export default defineConfig({ resolve: { alias: xmAliases(import.meta.url) }, });

The dist run (XM_TEST_TARGET=dist, see xmTestTarget) gets no entry for a published package, except <name>/src. Each @xmachines/* specifier of a published package then resolves through its exports map to dist/, and xmBuildOutput moves each src/ file that a test imports by path to its counterpart in dist/.

Parameters

ParameterTypeDescription
importMetaUrlstringPass import.meta.url from the calling config file. Used to locate the workspace root (the directory containing packages/).
targetXmTestTargetThe code to resolve to. The default reads XM_TEST_TARGET.

Returns

Record<string, string>