Configuration
Plugin options
Section titled “Plugin options”init adds the plugin to nx.json. Its options are the names of the targets it infers:
| Option | Default | Target |
|---|---|---|
devTargetName |
dev |
Development server |
buildTargetName |
build |
Production build |
previewTargetName |
preview |
Preview of the build |
checkTargetName |
check |
Type checking |
testTargetName |
test |
Vitest |
syncTargetName |
sync |
Type generation |
Rename a target when its name is already used for something else:
{ "plugins": [ { "plugin": "@geekvetica/nx-astro", "options": { "buildTargetName": "build-site" } } ]}Dependencies follow the new name: here preview runs build-site first. build-site itself runs the build and build-site targets of the libraries it depends on.
Inferred and generated targets
Section titled “Inferred and generated targets”There are two sources of targets:
- Inferred: the plugin gives every directory with an
astro.config.mjs,.jsor.tsits targets and the tagastro. They are not written to a file. - Generated: the application and import generators write
dev,build,preview,checkandsynctoproject.json. A target there wins over the inferred one of the same name.
Plugin options rename inferred targets only. In a generated project, rename the targets in its project.json too, or delete them there to use the inferred ones.
See the result of both with:
nx show project my-appChange a target
Section titled “Change a target”Change one project in its project.json. The rest of the inferred target stays:
{ "name": "my-app", "targets": { "dev": { "options": { "port": 4500 } } }}Change all projects that use an executor in nx.json:
{ "targetDefaults": { "@geekvetica/nx-astro:build": { "options": { "verbose": true } } }}Most Astro settings, such as the port, the site URL or the adapter, belong in the Astro config. The executors pass only the options that are set.
Output paths
Section titled “Output paths”The cached output of build is dist/<project root> in the workspace, such as dist/apps/my-app. Generated apps point outDir there:
import { defineConfig } from 'astro/config';
export default defineConfig({ outDir: '../../dist/apps/my-app',});If a project builds somewhere else, change outputs of its build target to the same place. Otherwise Nx restores nothing from the cache.
Leave a project out
Section titled “Leave a project out”To stop the plugin from handling a directory:
{ "plugins": [ { "plugin": "@geekvetica/nx-astro", "exclude": ["apps/legacy/**/*"] } ]}