[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationAuto-imports

Auto-imports

Which directories of a module are auto-imported and which Vite plugins it adds to the application, as declared in its frontend build file.

Nothing a module ships is auto-imported unless the module declares it. The declaration lives in an optional dms.frontend.build.ts next to dms.frontend.ts:

dms.frontend.build.ts ts
import { defineDmsFrontendBuild } from "#dms/frontend-build";

export default defineDmsFrontendBuild((build) => {
  build.registerAutoImports([
    "layers/*/app/composables",
    "layers/*/app/utils",
    "layers/*/app/types",
  ]);
});

Each entry is a directory relative to the module root, and it may hold glob patterns. Every export of the files under it is available to the whole application without an import, in scripts and templates. A module without the file has nothing auto-imported.

Private code stays private

app/build/ holds the private code of a module and is never auto-imported. A broader entry leaves it out. An entry that names it, or a directory outside the module, is ignored with a warning when Vite starts. The module's own files import that code by path.

A declaration file (.d.ts, .d.mts or .d.cts) under a declared directory is not auto-imported either. It has no runtime value, so a type the application should see without an import goes in a .ts file.

Linting the auto-imported names

ESLint's no-undef rule reports a name it sees no declaration for, and an auto-imported name is declared only in the auto-imports.d.ts that Vite writes. @antelopejs/dms-frontend/eslint-globals exports the names the renderer itself auto-imports, from Vue, frontend-module.ts and Nuxt UI, as an ESLint flat-config globals object:

eslint.config.mjs js
import dmsGlobals from "@antelopejs/dms-frontend/eslint-globals";
import globals from "globals";

export default [
  {
    files: ["**/*.{js,ts,vue}"],
    languageOptions: { globals: { ...globals.browser, ...dmsGlobals } },
    rules: { "no-undef": "error" },
  },
];

The names that the modules' declared directories export are not in it: each module owns those.

Vite plugins

registerVitePlugins, in the same file, adds Vite plugins to the application build. A module can use it to enforce its import boundaries in production builds, with an enforce: "pre" plugin whose resolveId or load hook fails on a forbidden module id.

The backend boundary needs no plugin. The package that holds a module's layer is its backend package. A file of any module that resolves to a file under the src directory of a backend package fails ajs dms dev, ajs dms build and worker builds. The check follows aliases and symlinks, and it also covers an id marked external. The frontend reaches the backend only through its HTTP interface.

dms.frontend.build.ts ts
import { defineDmsFrontendBuild } from "#dms/frontend-build";
import { boundaryPlugin } from "./build/boundary-plugin";

export default defineDmsFrontendBuild((build) => {
  build.registerVitePlugins(() => [boundaryPlugin()]);
});

The function you pass runs in the build process each time Vite loads its configuration, and once more for each web worker bundle. It returns real Vite plugin objects, as an array of objects that each have a name, or it returns nothing. As in a Vite configuration, false, null and undefined entries are skipped and nested arrays are flattened.

The function is synchronous, because Vite builds its configuration synchronously. A Promise is refused. The function creates the plugins, and the hooks of those plugins can be async.

The plugins run under ajs dms dev, ajs dms build and the preview. They also build each web worker that a frontend file starts with new Worker(new URL(...)), so a worker cannot import what a boundary plugin refuses. They come after the renderer's own plugins, in module order and then in the order of the calls. Vite orders plugins by their enforce first. The core resolver answers a relative or aliased import before a plugin without enforce sees it, so a plugin that must see every id sets enforce: "pre". A plugin's apply limits it to one command.

A value that is not an array of plugin objects fails Vite with a message that names the module. An error thrown by the function or by any hook of the plugins fails Vite the same way. That covers the function that configureServer returns, and plugins that are objects or class instances. The message starts with Frontend module <name>.

Where it runs

The file runs in Node.js when Vite starts, under ajs dms dev and ajs dms build, and never in the application. It can import #dms/frontend-build and Node.js built-ins, never the application's code. Vite restarts when the file changes.

A module that relies on auto-imports declares its public directories in this file and imports its app/build/ code by path.