-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adds support for build non-html pages * add non-html pages to the static build test suite * adds getStaticPaths() test for non-html pages * adds dev server tests for non-html pages * ading a changeset * updating changeset description * testing for building non-html files with async data * fixing typo in changeset docs
- Loading branch information
Tony Sullivan
authored
Feb 15, 2022
1 parent
b8dbba6
commit d6d35bc
Showing
20 changed files
with
369 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Support for non-HTML pages | ||
|
||
> ⚠️ This feature is currently only supported with the `--experimental-static-build` CLI flag. This feature may be refined over the next few weeks/months as SSR support is finalized. | ||
This adds support for generating non-HTML pages form `.js` and `.ts` pages during the build. Built file and extensions are based on the source file's name, ex: `src/pages/data.json.ts` will be built to `dist/data.json`. | ||
|
||
**Is this different from SSR?** Yes! This feature allows JSON, XML, etc. files to be output at build time. Keep an eye out for full SSR support if you need to build similar files when requested, for example as a serverless function in your deployment host. | ||
|
||
## Examples | ||
|
||
```typescript | ||
// src/pages/company.json.ts | ||
export async function get() { | ||
return { | ||
body: JSON.stringify({ | ||
name: 'Astro Technology Company', | ||
url: 'https://astro.build/' | ||
}) | ||
} | ||
} | ||
``` | ||
|
||
What about `getStaticPaths()`? It **just works**™. | ||
|
||
```typescript | ||
export async function getStaticPaths() { | ||
return [ | ||
{ params: { slug: 'thing1' }}, | ||
{ params: { slug: 'thing2' }} | ||
] | ||
} | ||
|
||
export async function get(params) { | ||
const { slug } = params | ||
|
||
return { | ||
body: // ...JSON.stringify() | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.