Skip to content

Configuration

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:

nx.json
{
"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.

There are two sources of targets:

  • Inferred: the plugin gives every directory with an astro.config.mjs, .js or .ts its targets and the tag astro. They are not written to a file.
  • Generated: the application and import generators write dev, build, preview, check and sync to project.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:

Terminal window
nx show project my-app

Change one project in its project.json. The rest of the inferred target stays:

apps/my-app/project.json
{
"name": "my-app",
"targets": {
"dev": { "options": { "port": 4500 } }
}
}

Change all projects that use an executor in nx.json:

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.

The cached output of build is dist/<project root> in the workspace, such as dist/apps/my-app. Generated apps point outDir there:

apps/my-app/astro.config.mjs
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.

To stop the plugin from handling a directory:

nx.json
{
"plugins": [
{
"plugin": "@geekvetica/nx-astro",
"exclude": ["apps/legacy/**/*"]
}
]
}
nx-astro 3.2.0 · MIT Developed by