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.
nx g @geekvetica/nx-astro:import --source=../my-astro-blog --name=blog --directory=apps/blognx dev blogThe source needs an Astro config, a package.json and an astro dependency.
What is copied
Section titled “What is copied”All files of the source, except:
- dependencies and output:
node_modules,dist,build,out,.astro,.vercel,.netlifyand caches, .git, editor settings, log files and lock files,- local environment files:
.env,.env.localand.env.<mode>.localof development, test and production..env.exampleis copied, - symbolic links, which are skipped.
What is changed
Section titled “What is changed”| 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.jsonand installed, exceptworkspace:,file:andlink:ones, tsconfig.jsongets a reference to the project,tsconfig.base.jsongets an alias for the project, such as@acme/blogforapps/blog/src/index.ts. Choose another one with--importPath.
What to do by hand
Section titled “What to do by hand”-
Output directory. Check that
outDiris in the Astro config. It is not added toastro.config.tsorastro.config.js, nor to a config in another form, such asexport 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',}); -
Compiler options. Only aliases are kept from the old
tsconfig.json. Add other options again, such as"strict": true. -
Environment files. Copy
.envfiles yourself. -
Scripts. The scripts of the old
package.jsonare gone. Use the Nx targets, or add targets toproject.json.
Check the result
Section titled “Check the result”nx show project blognx build blog