chore: release 1.6.0 (#2113)

This commit is contained in:
Marvin Hagemeister
2023-12-01 16:20:40 +01:00
committed by GitHub
parent bd372b9535
commit dace008611
12 changed files with 111 additions and 635 deletions
@@ -15,6 +15,9 @@ static file and can serve it immediately without any further processing. On
pages with islands, having to do no processing greatly speeds up page load
times.
Plugins can build static assets during ahead-of-time builds. This can be used to
preprocess or generate CSS files, for example.
## Creating an optimized build
To have Fresh optimize all the assets, run one of the following commands:
@@ -30,6 +33,10 @@ This will create a `_fresh` folder in the project directory. That folder
contains the optimized assets and a `snapshot.json` file which includes some
metadata for Fresh.
Any other static files generated by plugins will be stored in the
`_fresh/static` subfolder. They will be served the same as other
[static files](/docs/concepts/static-files.md).
> [info]: The `_fresh` folder should not be committed to the repository. Add an
> entry in the `.gitignore` file to ensure that it is not committed. Create that
> file at the root of your git repository if not present.
+13
View File
@@ -54,6 +54,19 @@ export default function BlogpostPage({ data }) {
}
```
This can also be achieved by throwing an error, if you're uninterested in
passing specific data to your 404 page:
```tsx
import { Handlers } from "$fresh/server.ts";
export const handler: Handlers = {
GET(_req, _ctx) {
throw new Deno.errors.NotFound();
},
};
```
### 500: Internal Server Error
The 500 page can be customized by creating a `_500.tsx` file in the `routes/`
+53 -1
View File
@@ -80,12 +80,17 @@ client.
The `render` hook needs to synchronously return a
[`PluginRenderResult`](https://deno.land/x/fresh/server.ts?s=PluginRenderResult)
object. Additional CSS and JS modules can be added to be injected into the page
by adding them to `styles` and `scripts` arrays in this object.
by adding them to `styles`, `links` and `scripts` arrays in this object. The
plugin can also replace the the HTML in side the `<body>`-element of the page by
including a `htmlText` string in this object.
`styles` are injected into the `<head>` of the page as inline CSS. Each entry
can define the CSS text to inject, as well as an optional `id` for the style
tag, and an optional `media` attribute for the style tag.
`links` are injected into the `<head>` of the page as `<link>` tags. A link tag
is created for each entry, with attributes from the entry's properties.
`scripts` define JavaScript/TypeScript modules to be injected into the page. The
possibly loaded modules need to be defined up front in the `Plugin#entrypoints`
property. Each defined module must be a JavaScript/TypeScript module that has a
@@ -123,6 +128,26 @@ rendering, plugin `render` hooks, and the
[`RenderFunction`](https://deno.land/x/fresh/server.ts?s=RenderFunction) that
may be provided to Fresh's `start` entrypoint in the `main.ts` file.
### Hook: `buildStart`
This hook is run at the start of the Fresh
[ahead-of-time build task](/docs/concepts/ahead-of-time-builds). It may be
synchronous or asynchronous.
The build start hook is called with the
[`ResolvedFreshConfig`](https://deno.land/x/fresh/src/server/types.ts?s=ResolvedFreshConfig)
object, which contains the full Fresh configuration.
This hook may be used to generate precompiled static assets. Any files saved to
the `static` subfolder of `config.build.outDir` (typically `_fresh`) will be
served the same as other [static files](/docs/concepts/static-files).
### Hook: `buildEnd`
This hook is run at the end of the Fresh
[ahead-of-time build task](/docs/concepts/ahead-of-time-builds). It may be
synchronous or asynchronous.
### Routes and Middlewares
You can create routes and middlewares that get loaded and rendered like the
@@ -138,3 +163,30 @@ For more examples see the [Concepts: Routing](/docs/concepts/routing) page.
To create a middleware you need to create a `MiddlewareHandler` function.
And to create a route you can create both a Handler and/or component.
A very basic example can be found
[here](https://github.com/denoland/fresh/blob/main/tests/fixture_plugin/utils/route-plugin.ts).
### Islands
Islands from plugins can be loaded by specifying a list of file paths in your
plugin. Those files will be treated by Fresh as if they had been placed inside
the `islands/` directory. They will be processed and bundled for the browser in
the same way.
```tsx my-island-plugin.ts
import { Plugin } from "$fresh/server.ts";
export default function myIslandPlugin(): Plugin {
return {
name: "my-island-plugin",
islands: {
baseLocation: import.meta.url,
paths: [
"./plugin/MyPluginIsland.tsx",
"./plugin/OtherPluginIsland.tsx",
],
},
};
}
```
@@ -65,6 +65,12 @@ export interface RouterOptions {
* @default {/(?:[^/]*_|[^/]*\.|)test\.(?:ts|tsx|mts|js|mjs|jsx|)\/*$/}
*/
ignoreFilePattern?: RegExp;
/**
* Serve fresh from a base path instead of from the root.
* "/foo/bar" -> http://localhost:8000/foo/bar
* @default {undefined}
*/
basePath?: string;
}
```
@@ -135,6 +141,30 @@ await start(manifest, { router: { trailingSlash: true } });
By default Fresh ignores test files which are co-located next routes and
islands. If you want, you can change the pattern Fresh uses ignore these files
### basePath
This setting allows you to serve a Fresh app from sub-path of a domain. A value
of `/foo/bar` would serve the app from `http://localhost:8000/foo/bar` instead
of `http://localhost:8000/` for example.
The `basePath` will be automatically applied to absolute links in your app. For
example, when the `basePath` is `/foo/bar`, linking to `/about` will
automatically become `/foo/bar/about`.
```jsx
<a href="/about">About</a>;
```
Rendered HTML:
```html
<a href="/foo/bar/about">About</a>
```
The `basePath` is also applied to the `src` and `srcset` attribute of
`<img>`-tags, the `href` attribute of `<link>` and the `src` attribute of
`<script>` tags.
## Server
Now that Deno has stabilized [Deno.serve](https://deno.land/api?s=Deno.serve)