Skip to content

Nx Astro Plugin

Nx plugin for Astro and Starlight applications.

  • 🚀 Generate Astro applications with various templates
  • 📚 Generate Starlight documentation sites
  • ⚡️ Support for React, Vue, Svelte, Solid, and Preact
  • 🎨 Tailwind CSS and SCSS support
  • 📝 TypeScript support
  • 🔧 ESLint and Prettier configuration
  • 🎯 Content Collections support
  • 🐳 Docker support with multi-stage builds
  • 🏗️ Complete Nx integration with Docker targets
Terminal window
pnpm add -D @surkyl/nx-astro

Generate a new Astro application:

Terminal window
nx g @surkyl/nx-astro:astro my-site

Options:

  • --template - Template to use (minimal, blog, portfolio, docs)
  • --port - Development server port (default: 4321)
  • --typescript - Use TypeScript (default: true)
  • --styling - Styling approach (css, scss, tailwind)
  • --framework - UI framework (none, react, vue, svelte, solid, preact)
  • --contentCollections - Include content collections (default: true)
  • --eslint - Add ESLint (default: true)
  • --prettier - Add Prettier (default: true)
  • --docker - Include Docker configuration (default: false)
  • --dockerRegistry - Docker registry for images (e.g., myorg, ghcr.io/myorg)

Example:

Terminal window
# Basic Astro app
nx g @surkyl/nx-astro:astro my-blog \
--template=blog \
--framework=react \
--styling=tailwind
# With Docker support
nx g @surkyl/nx-astro:astro my-site \
--docker \
--dockerRegistry=myorg

Generate a new Starlight documentation site:

Terminal window
nx g @surkyl/nx-astro:starlight my-docs

Options:

  • --title - Site title
  • --port - Development server port (default: 4322)
  • --typescript - Use TypeScript (default: true)
  • --i18n - Enable internationalization
  • --sidebar - Include sidebar navigation (default: true)
  • --search - Enable search (default: true)
  • --editLink - Include edit page links
  • --socialLinks - Include social media links
  • --customCss - Include custom CSS file
  • --docker - Include Docker configuration (default: false)
  • --dockerRegistry - Docker registry for images

Example:

Terminal window
nx g @surkyl/nx-astro:starlight api-docs \
--title="API Documentation" \
--i18n \
--search

Start the development server:

Terminal window
nx dev my-site

Options:

  • --port - Port number
  • --host - Host address
  • --open - Open browser automatically

Build for production:

Terminal window
nx build my-site

Preview the production build:

Terminal window
nx preview my-site

Options:

  • --port - Port number
  • --host - Host address

Run type checking:

Terminal window
nx check my-site

Options:

  • --watch - Watch for changes

When you generate an app with --docker flag, you get:

  • Dockerfile - Multi-stage build optimized for production
  • docker-compose.yml - Container orchestration configuration
  • .dockerignore - Optimized Docker ignore rules
  • Docker Nx targets - Integrated Docker commands

All Docker operations are available as Nx targets:

Terminal window
# Build Docker image
nx docker-build my-site
# Start container with Docker Compose
nx docker-compose-up my-site
# Stop container
nx docker-compose-down my-site
# Start existing container
nx docker-start my-site
# Stop running container
nx docker-stop my-site
# Tag image with git info
nx docker-tag my-site
# Push to registry
nx docker-push my-site
  1. Generate app with Docker support:

    Terminal window
    nx g @surkyl/nx-astro:astro my-app \
    --framework=react \
    --styling=tailwind \
    --docker \
    --dockerRegistry=ghcr.io/myorg
  2. Build the Docker image:

    Terminal window
    nx docker-build my-app
  3. Run with Docker Compose:

    Terminal window
    nx docker-compose-up my-app
  4. Push to registry:

    Terminal window
    nx docker-tag my-app
    nx docker-push my-app
  1. Generate an Astro site with React and Tailwind:

    Terminal window
    nx g @surkyl/nx-astro:astro my-app --framework=react --styling=tailwind
  2. Start development:

    Terminal window
    nx dev my-app
  3. Build for production:

    Terminal window
    nx build my-app
  4. Preview the build:

    Terminal window
    nx preview my-app

MIT