How it works
Task inference
Section titled “Task inference”Nx asks the plugin for projects. The plugin looks for astro.config.mjs, astro.config.js and astro.config.ts anywhere in the workspace, and for each one it adds to the project in that directory:
- the targets
dev,build,preview,checkandsync, - the target
test, ifvitestis in thepackage.jsonof the project or of the workspace root, - the tag
astroand the source root.
The config file is read, never run. A value that the plugin cannot read falls back to its default.
A directory without package.json and project.json is named after its directory, in lower case.
Targets in project.json and scripts in package.json win over inferred targets, see Configuration.
Project graph
Section titled “Project graph”Nx reads imports in TypeScript and JavaScript files. The plugin adds those in .astro files: in the frontmatter, in processed <script> elements, and dynamic imports in the markup. It resolves relative paths, TypeScript aliases, names of workspace packages and npm packages.
Only changed files are read again. Limits lists what is not followed.
Dependency sync
Section titled “Dependency sync”In a monorepo the packages are usually installed in the workspace root, while Astro looks for its integrations in the package.json of the project. So before each build the plugin copies astro and all @astrojs/* versions from the root package.json to the one of the project, and removes those from its dependencies that the root does not have. Everything else in that file stays.
The root is the place to update Astro. A project without a package.json is left alone, with a warning.
Executors
Section titled “Executors”The executors run the Astro and Vitest command lines with your package manager: pnpm exec, npx, yarn or bunx, from the workspace root and with the project as --root. They pass only the options that are set, so everything else comes from the Astro config.
The executors recognise the package manager by bun.lockb, pnpm-lock.yaml or yarn.lock, then by packageManager in the root package.json, then by bun.lock. Otherwise they use npm. The generators look at packageManager first.