Skip to content
⚠️ This project is depricated and will be deleted and removed from NPM in 2026. 🚨

Conditional Validation

When using the Starlight Spell Checker plugin with the Content Layer API, the plugin will automatically invalidate the content layer cache so that all words can be properly validated. To avoid unnecessary cache invalidation, it is recommended to conditionally use the plugin only when necessary.

By default, when adding the plugin to your Starlight configuration in the plugins array, the plugin will run for every build.

Instead of running the plugin for every build, you can conditionally use the plugin based on an environment variable. In the following example, the plugin will only run when the CHECK_SPELLING environment variable is set.

astro.config.mjs
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import starlightSpellChecker from 'starlight-spell-checker'
export default defineConfig({
integrations: [
starlight({
plugins: [starlightSpellChecker()],
plugins: process.env.CHECK_SPELLING ? [starlightSpellChecker()] : [],
title: 'My Docs',
}),
],
})

To run the plugin only when the CHECK_SPELLING environment variable is set, you can add the following script to your package.json file:

package.json
{
"scripts": {
"spellcheck": "CHECK_SPELLING=true astro build"
}
}

The spell check script can be used on CI pipelines to validate internal words in a dedicated workflow while deployment builds can skip the link validation step.