@ludena-studio/nx-astro 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +287 -0
- package/docs/configuration.md +528 -0
- package/docs/testing.md +322 -0
- package/executors/add/executor.d.ts +9 -0
- package/executors/add/executor.d.ts.map +1 -0
- package/executors/add/executor.js +51 -0
- package/executors/add/schema.json +20 -0
- package/executors/build/executor.d.ts +8 -0
- package/executors/build/executor.d.ts.map +1 -0
- package/executors/build/executor.js +43 -0
- package/executors/build/schema.json +15 -0
- package/executors/dev/executor.d.ts +10 -0
- package/executors/dev/executor.d.ts.map +1 -0
- package/executors/dev/executor.js +61 -0
- package/executors/dev/schema.json +25 -0
- package/executors/preview/executor.d.ts +9 -0
- package/executors/preview/executor.d.ts.map +1 -0
- package/executors/preview/executor.js +50 -0
- package/executors/preview/schema.json +20 -0
- package/executors/utils.d.ts +18 -0
- package/executors/utils.d.ts.map +1 -0
- package/executors/utils.js +80 -0
- package/executors.json +25 -0
- package/generators/app/files/.gitignore__template__ +9 -0
- package/generators/app/files/README.md__template__ +27 -0
- package/generators/app/files/astro.config.mjs__template__ +12 -0
- package/generators/app/files/src/env.d.ts__template__ +1 -0
- package/generators/app/files/src/pages/index.astro__template__ +20 -0
- package/generators/app/files/tsconfig.json__template__ +11 -0
- package/generators/app/files-tailwind/src/styles/global.css__template__ +1 -0
- package/generators/app/generator.d.ts +11 -0
- package/generators/app/generator.d.ts.map +1 -0
- package/generators/app/generator.js +123 -0
- package/generators/app/schema.json +49 -0
- package/generators.json +10 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/index.js +8 -0
- package/package.json +32 -0
- package/tsconfig.spec.json +13 -0
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
# Configuration Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This guide covers the complete configuration setup for the `@ludena-studio/nx-astro` plugin and how it integrates with your Nx monorepo.
|
|
6
|
+
|
|
7
|
+
## Project Setup
|
|
8
|
+
|
|
9
|
+
### Generated Project Structure
|
|
10
|
+
|
|
11
|
+
When you generate a new Astro app, the following structure is created:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
apps/my-astro-app/
|
|
15
|
+
├── src/
|
|
16
|
+
│ ├── pages/
|
|
17
|
+
│ │ └── index.astro
|
|
18
|
+
│ └── env.d.ts
|
|
19
|
+
├── astro.config.mjs
|
|
20
|
+
├── tsconfig.json
|
|
21
|
+
├── project.json
|
|
22
|
+
└── README.md
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### project.json Configuration
|
|
26
|
+
|
|
27
|
+
The generated `project.json` contains all Nx-specific configuration:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"name": "my-astro-app",
|
|
32
|
+
"projectType": "application",
|
|
33
|
+
"sourceRoot": "apps/my-astro-app/src",
|
|
34
|
+
"targets": {
|
|
35
|
+
"dev": {
|
|
36
|
+
"executor": "@ludena-studio/nx-astro:dev",
|
|
37
|
+
"options": {}
|
|
38
|
+
},
|
|
39
|
+
"serve": {
|
|
40
|
+
"executor": "@ludena-studio/nx-astro:dev",
|
|
41
|
+
"options": {}
|
|
42
|
+
},
|
|
43
|
+
"build": {
|
|
44
|
+
"executor": "@ludena-studio/nx-astro:build",
|
|
45
|
+
"options": {
|
|
46
|
+
"outputPath": "dist/apps/my-astro-app"
|
|
47
|
+
},
|
|
48
|
+
"outputs": ["{options.outputPath}"]
|
|
49
|
+
},
|
|
50
|
+
"preview": {
|
|
51
|
+
"executor": "@ludena-studio/nx-astro:preview",
|
|
52
|
+
"options": {},
|
|
53
|
+
"dependsOn": ["build"]
|
|
54
|
+
},
|
|
55
|
+
"add": {
|
|
56
|
+
"executor": "@ludena-studio/nx-astro:add",
|
|
57
|
+
"options": {}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"tags": []
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Executor Configuration
|
|
65
|
+
|
|
66
|
+
### Dev Executor
|
|
67
|
+
|
|
68
|
+
Development server configuration:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"targets": {
|
|
73
|
+
"dev": {
|
|
74
|
+
"executor": "@ludena-studio/nx-astro:dev",
|
|
75
|
+
"options": {
|
|
76
|
+
"port": 4321,
|
|
77
|
+
"host": false,
|
|
78
|
+
"open": false
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Available Options:**
|
|
86
|
+
- `port` (number) - Port number for dev server (default: 4321)
|
|
87
|
+
- `host` (string | boolean) - Hostname or `true` for 0.0.0.0
|
|
88
|
+
- `open` (boolean | string) - Open browser automatically, or specify URL path
|
|
89
|
+
|
|
90
|
+
**Examples:**
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Use default port
|
|
94
|
+
nx dev my-astro-app
|
|
95
|
+
|
|
96
|
+
# Custom port
|
|
97
|
+
nx dev my-astro-app --port 3000
|
|
98
|
+
|
|
99
|
+
# Listen on all network interfaces
|
|
100
|
+
nx dev my-astro-app --host
|
|
101
|
+
|
|
102
|
+
# Open browser on start
|
|
103
|
+
nx dev my-astro-app --open
|
|
104
|
+
|
|
105
|
+
# Open specific path
|
|
106
|
+
nx dev my-astro-app --open /about
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Build Executor
|
|
110
|
+
|
|
111
|
+
Production build configuration:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"targets": {
|
|
116
|
+
"build": {
|
|
117
|
+
"executor": "@ludena-studio/nx-astro:build",
|
|
118
|
+
"options": {
|
|
119
|
+
"outputPath": "dist/apps/my-astro-app"
|
|
120
|
+
},
|
|
121
|
+
"outputs": ["{options.outputPath}"],
|
|
122
|
+
"cache": true,
|
|
123
|
+
"dependsOn": ["^build"]
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Available Options:**
|
|
130
|
+
- `outputPath` (string) - Output directory for build artifacts
|
|
131
|
+
|
|
132
|
+
**Caching:** Build results are cached by Nx for faster subsequent builds.
|
|
133
|
+
|
|
134
|
+
### Preview Executor
|
|
135
|
+
|
|
136
|
+
Preview server configuration:
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"targets": {
|
|
141
|
+
"preview": {
|
|
142
|
+
"executor": "@ludena-studio/nx-astro:preview",
|
|
143
|
+
"options": {
|
|
144
|
+
"port": 4321,
|
|
145
|
+
"host": false
|
|
146
|
+
},
|
|
147
|
+
"dependsOn": ["build"]
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Available Options:**
|
|
154
|
+
- `port` (number) - Port number for preview server
|
|
155
|
+
- `host` (string | boolean) - Hostname or `true` for 0.0.0.0
|
|
156
|
+
|
|
157
|
+
**Note:** Preview always depends on build target.
|
|
158
|
+
|
|
159
|
+
### Add Executor
|
|
160
|
+
|
|
161
|
+
Integration management configuration:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"targets": {
|
|
166
|
+
"add": {
|
|
167
|
+
"executor": "@ludena-studio/nx-astro:add",
|
|
168
|
+
"options": {
|
|
169
|
+
"integration": "tailwind",
|
|
170
|
+
"yes": false
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Available Options:**
|
|
178
|
+
- `integration` (string, required) - Integration name
|
|
179
|
+
- `yes` (boolean) - Skip confirmation prompts
|
|
180
|
+
|
|
181
|
+
**Supported Integrations:**
|
|
182
|
+
- `tailwind` - Tailwind CSS
|
|
183
|
+
- `react` - React framework
|
|
184
|
+
- `vue` - Vue framework
|
|
185
|
+
- `svelte` - Svelte framework
|
|
186
|
+
- `solid` - Solid.js framework
|
|
187
|
+
- `mdx` - MDX support
|
|
188
|
+
- `sitemap` - Sitemap generation
|
|
189
|
+
- `partytown` - Partytown third-party scripts
|
|
190
|
+
|
|
191
|
+
## TypeScript Configuration
|
|
192
|
+
|
|
193
|
+
### tsconfig.json
|
|
194
|
+
|
|
195
|
+
Generated TypeScript configuration:
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{
|
|
199
|
+
"extends": "../../tsconfig.base.json",
|
|
200
|
+
"compilerOptions": {
|
|
201
|
+
"jsx": "react-jsx",
|
|
202
|
+
"jsxImportSource": "astro",
|
|
203
|
+
"moduleResolution": "bundler",
|
|
204
|
+
"module": "ESNext",
|
|
205
|
+
"target": "ESNext",
|
|
206
|
+
"lib": ["ESNext", "DOM"],
|
|
207
|
+
"types": ["astro/client"]
|
|
208
|
+
},
|
|
209
|
+
"include": ["src/**/*"],
|
|
210
|
+
"exclude": ["node_modules", "dist"]
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Strict Mode
|
|
215
|
+
|
|
216
|
+
Enable strict TypeScript checking:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
nx g @ludena-studio/nx-astro:app my-app --strict
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
This adds:
|
|
223
|
+
```json
|
|
224
|
+
{
|
|
225
|
+
"compilerOptions": {
|
|
226
|
+
"strict": true,
|
|
227
|
+
"noUncheckedIndexedAccess": true,
|
|
228
|
+
"noImplicitAny": true
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Astro Configuration
|
|
234
|
+
|
|
235
|
+
### astro.config.mjs
|
|
236
|
+
|
|
237
|
+
Basic Astro configuration:
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
import { defineConfig } from 'astro/config';
|
|
241
|
+
|
|
242
|
+
export default defineConfig({
|
|
243
|
+
// Configuration options
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Adding Integrations
|
|
248
|
+
|
|
249
|
+
Automatically via executor:
|
|
250
|
+
```bash
|
|
251
|
+
nx add my-astro-app --integration=tailwind
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Manually in `astro.config.mjs`:
|
|
255
|
+
```javascript
|
|
256
|
+
import { defineConfig } from 'astro/config';
|
|
257
|
+
import tailwind from '@astrojs/tailwind';
|
|
258
|
+
|
|
259
|
+
export default defineConfig({
|
|
260
|
+
integrations: [tailwind()],
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Output Options
|
|
265
|
+
|
|
266
|
+
Configure output for different deployment targets:
|
|
267
|
+
|
|
268
|
+
```javascript
|
|
269
|
+
export default defineConfig({
|
|
270
|
+
output: 'static', // or 'server' or 'hybrid'
|
|
271
|
+
adapter: adapter(), // for server/hybrid
|
|
272
|
+
});
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Workspace Integration
|
|
276
|
+
|
|
277
|
+
### Nx Caching
|
|
278
|
+
|
|
279
|
+
Enable caching for faster builds:
|
|
280
|
+
|
|
281
|
+
```json
|
|
282
|
+
{
|
|
283
|
+
"targets": {
|
|
284
|
+
"build": {
|
|
285
|
+
"cache": true,
|
|
286
|
+
"outputs": ["{options.outputPath}"]
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Task Dependencies
|
|
293
|
+
|
|
294
|
+
Configure task execution order:
|
|
295
|
+
|
|
296
|
+
```json
|
|
297
|
+
{
|
|
298
|
+
"targets": {
|
|
299
|
+
"build": {
|
|
300
|
+
"dependsOn": ["^build", "typecheck"]
|
|
301
|
+
},
|
|
302
|
+
"preview": {
|
|
303
|
+
"dependsOn": ["build"]
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Tags and Constraints
|
|
310
|
+
|
|
311
|
+
Organize projects with tags:
|
|
312
|
+
|
|
313
|
+
```json
|
|
314
|
+
{
|
|
315
|
+
"tags": ["scope:web", "type:app", "framework:astro"]
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Use in `nx.json` for constraints:
|
|
320
|
+
|
|
321
|
+
```json
|
|
322
|
+
{
|
|
323
|
+
"namedInputs": {
|
|
324
|
+
"default": ["{projectRoot}/**/*"],
|
|
325
|
+
"production": ["default", "!{projectRoot}/**/*.spec.ts"]
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Environment Variables
|
|
331
|
+
|
|
332
|
+
### Using .env Files
|
|
333
|
+
|
|
334
|
+
Create `.env` file in project root:
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
# .env
|
|
338
|
+
PUBLIC_API_URL=https://api.example.com
|
|
339
|
+
SECRET_KEY=your-secret-key
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Access in Astro:
|
|
343
|
+
|
|
344
|
+
```astro
|
|
345
|
+
---
|
|
346
|
+
const apiUrl = import.meta.env.PUBLIC_API_URL;
|
|
347
|
+
// Only PUBLIC_* vars are available client-side
|
|
348
|
+
---
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### Nx Integration
|
|
352
|
+
|
|
353
|
+
Define in `project.json`:
|
|
354
|
+
|
|
355
|
+
```json
|
|
356
|
+
{
|
|
357
|
+
"targets": {
|
|
358
|
+
"build": {
|
|
359
|
+
"options": {
|
|
360
|
+
"env": {
|
|
361
|
+
"NODE_ENV": "production"
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## Advanced Configuration
|
|
370
|
+
|
|
371
|
+
### Custom Scripts
|
|
372
|
+
|
|
373
|
+
Add custom npm scripts in `package.json`:
|
|
374
|
+
|
|
375
|
+
```json
|
|
376
|
+
{
|
|
377
|
+
"scripts": {
|
|
378
|
+
"dev": "nx dev my-astro-app",
|
|
379
|
+
"build": "nx build my-astro-app",
|
|
380
|
+
"preview": "nx preview my-astro-app"
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Multiple Configurations
|
|
386
|
+
|
|
387
|
+
Create configuration-specific targets:
|
|
388
|
+
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"targets": {
|
|
392
|
+
"build": {
|
|
393
|
+
"executor": "@ludena-studio/nx-astro:build",
|
|
394
|
+
"configurations": {
|
|
395
|
+
"production": {
|
|
396
|
+
"outputPath": "dist/apps/my-astro-app/production"
|
|
397
|
+
},
|
|
398
|
+
"staging": {
|
|
399
|
+
"outputPath": "dist/apps/my-astro-app/staging"
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Run with:
|
|
408
|
+
```bash
|
|
409
|
+
nx build my-astro-app --configuration=production
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### Workspace Libraries
|
|
413
|
+
|
|
414
|
+
Share code between apps using workspace libraries:
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
// libs/shared/ui/src/index.ts
|
|
418
|
+
export { Button } from './lib/button';
|
|
419
|
+
|
|
420
|
+
// apps/my-astro-app/src/pages/index.astro
|
|
421
|
+
---
|
|
422
|
+
import { Button } from '@my-org/shared-ui';
|
|
423
|
+
---
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
Configure path mapping in `tsconfig.base.json`:
|
|
427
|
+
|
|
428
|
+
```json
|
|
429
|
+
{
|
|
430
|
+
"compilerOptions": {
|
|
431
|
+
"paths": {
|
|
432
|
+
"@my-org/shared-ui": ["libs/shared/ui/src/index.ts"]
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
## Migration Guide
|
|
439
|
+
|
|
440
|
+
### From Standalone Astro
|
|
441
|
+
|
|
442
|
+
1. **Move project to Nx workspace:**
|
|
443
|
+
```bash
|
|
444
|
+
mv my-astro-project apps/
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
2. **Create project.json:**
|
|
448
|
+
```bash
|
|
449
|
+
nx g @ludena-studio/nx-astro:app my-astro-project --skipInstall
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
3. **Update imports in `astro.config.mjs`** if using workspace libs
|
|
453
|
+
|
|
454
|
+
4. **Update `tsconfig.json`** to extend workspace base config
|
|
455
|
+
|
|
456
|
+
### From Other Framework
|
|
457
|
+
|
|
458
|
+
Follow the Astro migration guide for your framework:
|
|
459
|
+
- [React to Astro](https://docs.astro.build/en/guides/migrate-to-astro/from-create-react-app/)
|
|
460
|
+
- [Vue to Astro](https://docs.astro.build/en/guides/migrate-to-astro/from-vue/)
|
|
461
|
+
- [Next.js to Astro](https://docs.astro.build/en/guides/migrate-to-astro/from-nextjs/)
|
|
462
|
+
|
|
463
|
+
## Troubleshooting
|
|
464
|
+
|
|
465
|
+
### Build Output Location
|
|
466
|
+
|
|
467
|
+
If build output is not where expected, verify `outputPath` in `project.json`:
|
|
468
|
+
|
|
469
|
+
```json
|
|
470
|
+
{
|
|
471
|
+
"targets": {
|
|
472
|
+
"build": {
|
|
473
|
+
"options": {
|
|
474
|
+
"outputPath": "dist/apps/my-astro-app"
|
|
475
|
+
},
|
|
476
|
+
"outputs": ["{options.outputPath}"]
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Path Aliases Not Working
|
|
483
|
+
|
|
484
|
+
Ensure `tsconfig.base.json` paths are correctly configured and `astro.config.mjs` includes:
|
|
485
|
+
|
|
486
|
+
```javascript
|
|
487
|
+
import { defineConfig } from 'astro/config';
|
|
488
|
+
|
|
489
|
+
export default defineConfig({
|
|
490
|
+
vite: {
|
|
491
|
+
resolve: {
|
|
492
|
+
alias: {
|
|
493
|
+
'@my-org/shared': '/libs/shared/src',
|
|
494
|
+
},
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### Nx Cache Not Working
|
|
501
|
+
|
|
502
|
+
Verify cache configuration:
|
|
503
|
+
|
|
504
|
+
```json
|
|
505
|
+
{
|
|
506
|
+
"targets": {
|
|
507
|
+
"build": {
|
|
508
|
+
"cache": true,
|
|
509
|
+
"outputs": ["{options.outputPath}"],
|
|
510
|
+
"inputs": [
|
|
511
|
+
"default",
|
|
512
|
+
"^production"
|
|
513
|
+
]
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
Clear cache if needed:
|
|
520
|
+
```bash
|
|
521
|
+
nx reset
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
## Resources
|
|
525
|
+
|
|
526
|
+
- [Astro Configuration Reference](https://docs.astro.build/en/reference/configuration-reference/)
|
|
527
|
+
- [Nx Project Configuration](https://nx.dev/reference/project-configuration)
|
|
528
|
+
- [TypeScript Configuration](https://www.typescriptlang.org/tsconfig)
|