Skip to content

Import a project

The import generator copies an Astro project into the workspace and adapts the parts that differ in a monorepo. The source is not changed.

Terminal window
nx g @geekvetica/nx-astro:import --source=../my-astro-blog --name=blog --directory=apps/blog
nx dev blog

The source needs an Astro config, a package.json and an astro dependency.

All files of the source, except:

  • dependencies and output: node_modules, dist, build, out, .astro, .vercel, .netlify and caches,
  • .git, editor settings, log files and lock files,
  • local environment files: .env, .env.local and .env.<mode>.local of development, test and production. .env.example is copied,
  • symbolic links, which are skipped.
File Change
astro.config.mjs outDir is set to dist/<project root> in the workspace, if the config is written as defineConfig({ … }) or export default { … } and the file does not mention outDir
package.json Replaced by a minimal one with astro and the @astrojs/* packages
tsconfig.json, tsconfig.base.json Replaced. The aliases of the project are kept, and the aliases of the workspace are added
project.json Created, with the targets dev, build, preview, check and sync

In the workspace root:

  • the dependencies of the project are added to package.json and installed, except workspace:, file: and link: ones,
  • tsconfig.json gets a reference to the project,
  • tsconfig.base.json gets an alias for the project, such as @acme/blog for apps/blog/src/index.ts. Choose another one with --importPath.
  1. Output directory. Check that outDir is in the Astro config. It is not added to astro.config.ts or astro.config.js, nor to a config in another form, such as export default config. Add it there yourself, so that the output lands where Nx caches it:

    apps/blog/astro.config.ts
    import { defineConfig } from 'astro/config';
    export default defineConfig({
    outDir: '../../dist/apps/blog',
    });
  2. Compiler options. Only aliases are kept from the old tsconfig.json. Add other options again, such as "strict": true.

  3. Environment files. Copy .env files yourself.

  4. Scripts. The scripts of the old package.json are gone. Use the Nx targets, or add targets to project.json.

Terminal window
nx show project blog
nx build blog
nx-astro 3.2.0 · MIT Developed by