Start renaming

This commit is contained in:
2026-11-11 11:45:20 -03:00
parent ae22ec5276
commit 216d54a0ae
179 changed files with 890 additions and 449 deletions
@@ -29,7 +29,7 @@ If you need a particular commit (for testing specific fixes or features):
"update": "deno run -A -r jsr:@fresh/update ."
},
"imports": {
- "$fresh/": "jsr:@fresh/core@^2.0.0",
- "$fresh/": "jsr:@paulaboks/sweet@^2.0.0",
+ "$fresh/": "https://raw.githubusercontent.com/denoland/fresh/your-commit-hash/",
"preact": "npm:preact@^10.26.9",
"@preact/signals": "npm:@preact/signals@^2.2.0"
@@ -59,7 +59,7 @@ For testing your own fork or PR:
### Using JSR
```sh Terminal
deno run -A -r jsr:@fresh/init@2.0.0-alpha.35
deno run -A -r jsr:@paulaboks/sweet-init@2.0.0-alpha.35
```
### From local source
+52 -52
View File
@@ -6,51 +6,51 @@ description: |
This page lists all public exports from Fresh's entry points.
> [info]: You can also explore Fresh's full API documentation on JSR:
> [`@fresh/core`](https://jsr.io/@fresh/core/doc)
> [`@paulaboks/sweet`](https://jsr.io/@paulaboks/sweet/doc)
## `fresh`
The main entry point for server-side code.
```ts
import { App, createDefine, HttpError, page, staticFiles } from "fresh";
import { App, createDefine, HttpError, page, staticFiles } from "sweet";
```
| Export | Kind | Description |
| --------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------- |
| [`App`](https://jsr.io/@fresh/core/doc/~/App) | Class | The main application class. See [App](/docs/concepts/app). |
| [`staticFiles`](https://jsr.io/@fresh/core/doc/~/staticFiles) | Function | Middleware for serving static files. See [Static Files](/docs/concepts/static-files). |
| [`createDefine`](https://jsr.io/@fresh/core/doc/~/createDefine) | Function | Create type-safe `define.*` helpers. See [Define Helpers](/docs/advanced/define). |
| [`page`](https://jsr.io/@fresh/core/doc/~/page) | Function | Return data from a handler to a page component. See [Data Fetching](/docs/concepts/data-fetching). |
| [`HttpError`](https://jsr.io/@fresh/core/doc/~/HttpError) | Class | Throw HTTP errors with status codes. See [Error Handling](/docs/advanced/error-handling). |
| [`cors`](https://jsr.io/@fresh/core/doc/~/cors) | Function | CORS middleware. See [cors](/docs/plugins/cors). |
| [`csrf`](https://jsr.io/@fresh/core/doc/~/csrf) | Function | CSRF protection middleware. See [csrf](/docs/plugins/csrf). |
| [`csp`](https://jsr.io/@fresh/core/doc/~/csp) | Function | Content Security Policy middleware. See [csp](/docs/plugins/csp). |
| [`trailingSlashes`](https://jsr.io/@fresh/core/doc/~/trailingSlashes) | Function | Trailing slash enforcement middleware. See [trailingSlashes](/docs/plugins/trailing-slashes). |
| Export | Kind | Description |
| -------------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------- |
| [`App`](https://jsr.io/@paulaboks/sweet/doc/~/App) | Class | The main application class. See [App](/docs/concepts/app). |
| [`staticFiles`](https://jsr.io/@paulaboks/sweet/doc/~/staticFiles) | Function | Middleware for serving static files. See [Static Files](/docs/concepts/static-files). |
| [`createDefine`](https://jsr.io/@paulaboks/sweet/doc/~/createDefine) | Function | Create type-safe `define.*` helpers. See [Define Helpers](/docs/advanced/define). |
| [`page`](https://jsr.io/@paulaboks/sweet/doc/~/page) | Function | Return data from a handler to a page component. See [Data Fetching](/docs/concepts/data-fetching). |
| [`HttpError`](https://jsr.io/@paulaboks/sweet/doc/~/HttpError) | Class | Throw HTTP errors with status codes. See [Error Handling](/docs/advanced/error-handling). |
| [`cors`](https://jsr.io/@paulaboks/sweet/doc/~/cors) | Function | CORS middleware. See [cors](/docs/plugins/cors). |
| [`csrf`](https://jsr.io/@paulaboks/sweet/doc/~/csrf) | Function | CSRF protection middleware. See [csrf](/docs/plugins/csrf). |
| [`csp`](https://jsr.io/@paulaboks/sweet/doc/~/csp) | Function | Content Security Policy middleware. See [csp](/docs/plugins/csp). |
| [`trailingSlashes`](https://jsr.io/@paulaboks/sweet/doc/~/trailingSlashes) | Function | Trailing slash enforcement middleware. See [trailingSlashes](/docs/plugins/trailing-slashes). |
**Types:**
| Export | Kind | Description |
| --------------------------------------------------------------------------------------------------------------------------------------------- | --------- | --------------------------------------------------------------------------- |
| [`Context`](https://jsr.io/@fresh/core/doc/~/Context) / [`FreshContext`](https://jsr.io/@fresh/core/doc/~/FreshContext) | Interface | The request context passed to all middlewares and handlers. |
| [`PageProps`](https://jsr.io/@fresh/core/doc/~/PageProps) | Type | Props received by page components (`data`, `url`, `params`, `state`, etc.). |
| [`Middleware`](https://jsr.io/@fresh/core/doc/~/Middleware) / [`MiddlewareFn`](https://jsr.io/@fresh/core/doc/~/MiddlewareFn) | Type | Middleware function type. |
| [`HandlerFn`](https://jsr.io/@fresh/core/doc/~/HandlerFn) | Type | Single handler function type. |
| [`HandlerByMethod`](https://jsr.io/@fresh/core/doc/~/HandlerByMethod) | Type | Object with per-method handler functions. |
| [`RouteHandler`](https://jsr.io/@fresh/core/doc/~/RouteHandler) | Type | Union of `HandlerFn` and `HandlerByMethod`. |
| [`PageResponse`](https://jsr.io/@fresh/core/doc/~/PageResponse) | Type | Return type of `page()`. |
| [`RouteConfig`](https://jsr.io/@fresh/core/doc/~/RouteConfig) | Interface | Route configuration (`routeOverride`, `skipInheritedLayouts`, etc.). |
| [`LayoutConfig`](https://jsr.io/@fresh/core/doc/~/LayoutConfig) | Interface | Layout configuration (`skipInheritedLayouts`, `skipAppWrapper`). |
| [`Define`](https://jsr.io/@fresh/core/doc/~/Define) | Interface | Type of the object returned by `createDefine()`. |
| [`FreshConfig`](https://jsr.io/@fresh/core/doc/~/FreshConfig) / [`ResolvedFreshConfig`](https://jsr.io/@fresh/core/doc/~/ResolvedFreshConfig) | Interface | App configuration types. |
| [`ListenOptions`](https://jsr.io/@fresh/core/doc/~/ListenOptions) | Interface | Options for `app.listen()`. |
| [`Island`](https://jsr.io/@fresh/core/doc/~/Island) | Type | Island component type. |
| [`Method`](https://jsr.io/@fresh/core/doc/~/Method) | Type | HTTP method union type. |
| [`RouteData`](https://jsr.io/@fresh/core/doc/~/RouteData) | Type | Data type returned by route handlers via `page()`. |
| [`Lazy`](https://jsr.io/@fresh/core/doc/~/Lazy) / [`MaybeLazy`](https://jsr.io/@fresh/core/doc/~/MaybeLazy) | Type | Utility types for lazily-loaded routes and middleware. |
| [`CORSOptions`](https://jsr.io/@fresh/core/doc/~/CORSOptions) | Interface | Options for `cors()`. |
| [`CsrfOptions`](https://jsr.io/@fresh/core/doc/~/CsrfOptions) | Interface | Options for `csrf()`. |
| [`CSPOptions`](https://jsr.io/@fresh/core/doc/~/CSPOptions) | Interface | Options for `csp()`. |
| Export | Kind | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | --------------------------------------------------------------------------- |
| [`Context`](https://jsr.io/@paulaboks/sweet/doc/~/Context) / [`FreshContext`](https://jsr.io/@paulaboks/sweet/doc/~/FreshContext) | Interface | The request context passed to all middlewares and handlers. |
| [`PageProps`](https://jsr.io/@paulaboks/sweet/doc/~/PageProps) | Type | Props received by page components (`data`, `url`, `params`, `state`, etc.). |
| [`Middleware`](https://jsr.io/@paulaboks/sweet/doc/~/Middleware) / [`MiddlewareFn`](https://jsr.io/@paulaboks/sweet/doc/~/MiddlewareFn) | Type | Middleware function type. |
| [`HandlerFn`](https://jsr.io/@paulaboks/sweet/doc/~/HandlerFn) | Type | Single handler function type. |
| [`HandlerByMethod`](https://jsr.io/@paulaboks/sweet/doc/~/HandlerByMethod) | Type | Object with per-method handler functions. |
| [`RouteHandler`](https://jsr.io/@paulaboks/sweet/doc/~/RouteHandler) | Type | Union of `HandlerFn` and `HandlerByMethod`. |
| [`PageResponse`](https://jsr.io/@paulaboks/sweet/doc/~/PageResponse) | Type | Return type of `page()`. |
| [`RouteConfig`](https://jsr.io/@paulaboks/sweet/doc/~/RouteConfig) | Interface | Route configuration (`routeOverride`, `skipInheritedLayouts`, etc.). |
| [`LayoutConfig`](https://jsr.io/@paulaboks/sweet/doc/~/LayoutConfig) | Interface | Layout configuration (`skipInheritedLayouts`, `skipAppWrapper`). |
| [`Define`](https://jsr.io/@paulaboks/sweet/doc/~/Define) | Interface | Type of the object returned by `createDefine()`. |
| [`FreshConfig`](https://jsr.io/@paulaboks/sweet/doc/~/FreshConfig) / [`ResolvedFreshConfig`](https://jsr.io/@paulaboks/sweet/doc/~/ResolvedFreshConfig) | Interface | App configuration types. |
| [`ListenOptions`](https://jsr.io/@paulaboks/sweet/doc/~/ListenOptions) | Interface | Options for `app.listen()`. |
| [`Island`](https://jsr.io/@paulaboks/sweet/doc/~/Island) | Type | Island component type. |
| [`Method`](https://jsr.io/@paulaboks/sweet/doc/~/Method) | Type | HTTP method union type. |
| [`RouteData`](https://jsr.io/@paulaboks/sweet/doc/~/RouteData) | Type | Data type returned by route handlers via `page()`. |
| [`Lazy`](https://jsr.io/@paulaboks/sweet/doc/~/Lazy) / [`MaybeLazy`](https://jsr.io/@paulaboks/sweet/doc/~/MaybeLazy) | Type | Utility types for lazily-loaded routes and middleware. |
| [`CORSOptions`](https://jsr.io/@paulaboks/sweet/doc/~/CORSOptions) | Interface | Options for `cors()`. |
| [`CsrfOptions`](https://jsr.io/@paulaboks/sweet/doc/~/CsrfOptions) | Interface | Options for `csrf()`. |
| [`CSPOptions`](https://jsr.io/@paulaboks/sweet/doc/~/CSPOptions) | Interface | Options for `csp()`. |
## `fresh/runtime`
@@ -65,34 +65,34 @@ import {
HttpError,
IS_BROWSER,
Partial,
} from "fresh/runtime";
} from "sweet/runtime";
```
| Export | Kind | Description |
| --------------------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------- |
| [`IS_BROWSER`](https://jsr.io/@fresh/core/doc/runtime/~/IS_BROWSER) | Constant | `true` in the browser, `false` on the server. Use to guard browser-only code. |
| [`asset`](https://jsr.io/@fresh/core/doc/runtime/~/asset) | Function | Add cache-busting query params to asset URLs. See [Static Files](/docs/concepts/static-files). |
| [`assetSrcSet`](https://jsr.io/@fresh/core/doc/runtime/~/assetSrcSet) | Function | Apply `asset()` to all URLs in a `srcset` string. |
| [`Partial`](https://jsr.io/@fresh/core/doc/runtime/~/Partial) | Component | Mark a region for partial updates. See [Partials](/docs/advanced/partials). |
| [`Head`](https://jsr.io/@fresh/core/doc/runtime/~/Head) | Component | Add elements to the document `<head>`. See [<head> element](/docs/advanced/head). |
| [`HttpError`](https://jsr.io/@fresh/core/doc/runtime/~/HttpError) | Class | HTTP error class (re-exported from `fresh`). |
| Export | Kind | Description |
| -------------------------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------- |
| [`IS_BROWSER`](https://jsr.io/@paulaboks/sweet/doc/runtime/~/IS_BROWSER) | Constant | `true` in the browser, `false` on the server. Use to guard browser-only code. |
| [`asset`](https://jsr.io/@paulaboks/sweet/doc/runtime/~/asset) | Function | Add cache-busting query params to asset URLs. See [Static Files](/docs/concepts/static-files). |
| [`assetSrcSet`](https://jsr.io/@paulaboks/sweet/doc/runtime/~/assetSrcSet) | Function | Apply `asset()` to all URLs in a `srcset` string. |
| [`Partial`](https://jsr.io/@paulaboks/sweet/doc/runtime/~/Partial) | Component | Mark a region for partial updates. See [Partials](/docs/advanced/partials). |
| [`Head`](https://jsr.io/@paulaboks/sweet/doc/runtime/~/Head) | Component | Add elements to the document `<head>`. See [<head> element](/docs/advanced/head). |
| [`HttpError`](https://jsr.io/@paulaboks/sweet/doc/runtime/~/HttpError) | Class | HTTP error class (re-exported from `fresh`). |
## `fresh/dev`
Development and build tools. Only used in `dev.ts` (legacy) or build scripts.
```ts
import { Builder } from "fresh/dev";
import { Builder } from "sweet/dev";
```
| Export | Kind | Description |
| --------------------------------------------------------- | ----- | ---------------------------------------------------------------------- |
| [`Builder`](https://jsr.io/@fresh/core/doc/dev/~/Builder) | Class | Pre-Vite build system (legacy). See [Builder](/docs/advanced/builder). |
| Export | Kind | Description |
| -------------------------------------------------------------- | ----- | ---------------------------------------------------------------------- |
| [`Builder`](https://jsr.io/@paulaboks/sweet/doc/dev/~/Builder) | Class | Pre-Vite build system (legacy). See [Builder](/docs/advanced/builder). |
**Types:**
| Export | Kind | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------------------------- |
| [`BuildOptions`](https://jsr.io/@fresh/core/doc/dev/~/BuildOptions) | Interface | Options for `new Builder()`. |
| [`ResolvedBuildConfig`](https://jsr.io/@fresh/core/doc/dev/~/ResolvedBuildConfig) | Interface | Resolved build configuration. |
| [`OnTransformArgs`](https://jsr.io/@fresh/core/doc/dev/~/OnTransformArgs) / [`OnTransformOptions`](https://jsr.io/@fresh/core/doc/dev/~/OnTransformOptions) / [`TransformFn`](https://jsr.io/@fresh/core/doc/dev/~/TransformFn) | Type | Build plugin hook types. |
| Export | Kind | Description |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------------------------- |
| [`BuildOptions`](https://jsr.io/@paulaboks/sweet/doc/dev/~/BuildOptions) | Interface | Options for `new Builder()`. |
| [`ResolvedBuildConfig`](https://jsr.io/@paulaboks/sweet/doc/dev/~/ResolvedBuildConfig) | Interface | Resolved build configuration. |
| [`OnTransformArgs`](https://jsr.io/@paulaboks/sweet/doc/dev/~/OnTransformArgs) / [`OnTransformOptions`](https://jsr.io/@paulaboks/sweet/doc/dev/~/OnTransformOptions) / [`TransformFn`](https://jsr.io/@paulaboks/sweet/doc/dev/~/TransformFn) | Type | Build plugin hook types. |
+1 -1
View File
@@ -111,7 +111,7 @@ routes that return JSON, or pages that need a completely different HTML
structure. Use `skipAppWrapper` in the route config:
```tsx routes/embed.tsx
import { type RouteConfig } from "fresh";
import { type RouteConfig } from "sweet";
import { define } from "../utils.ts";
export const config: RouteConfig = {
+6 -6
View File
@@ -11,7 +11,7 @@ The `Builder` class is used to generate production assets of your app. You'll
typically find it being created inside your project's `dev.ts` file.
```ts dev.ts
import { Builder } from "fresh/dev";
import { Builder } from "sweet/dev";
const builder = new Builder({ target: "safari12" });
@@ -167,12 +167,12 @@ that.
}
```
2. Run `deno install jsr:@fresh/plugin-tailwind`
2. Run `deno install jsr:@paulaboks/sweet-tailwind`
3. Update `dev.ts`:
```diff dev.ts
import { Builder } from "fresh/dev";
+ import { tailwind } from "@fresh/plugin-tailwind";
import { Builder } from "sweet/dev";
+ import { tailwind } from "@paulaboks/sweet-tailwind";
const builder = new Builder();
+ tailwind(builder);
@@ -205,8 +205,8 @@ If you can't update to the current version of tailwindcss we have a dedicated
decided on your own when it's best to update to v4.
```ts dev.ts
import { Builder } from "fresh/dev";
import { tailwind } from "@fresh/plugin-tailwind-v3";
import { Builder } from "sweet/dev";
import { tailwind } from "@paulaboks/sweet-tailwind-v3";
tailwind(builder, {});
```
+1 -1
View File
@@ -30,7 +30,7 @@ export async function otherMiddleware(ctx: Context<State>): Promise<Response> {
With define helpers:
```ts util.ts
import { createDefine } from "fresh";
import { createDefine } from "sweet";
// Setup, do this once in a file and import it everywhere else.
export const define = createDefine<{ foo: string }>();
+4 -4
View File
@@ -21,7 +21,7 @@ Fresh supports two kind of error pages:
To add an error page use [`app.onError()`](/docs/concepts/app#onerror).
```ts main.ts
import { App } from "fresh";
import { App } from "sweet";
const app = new App()
.onError("*", (ctx) => {
@@ -77,13 +77,13 @@ If you need to bail out of execution and need to respond with a particular HTTP
error code, you can use Fresh's `HttpError` class:
```ts
import { HttpError } from "fresh";
import { HttpError } from "sweet";
```
`HttpError` takes a status code and an optional message:
```ts middleware/auth.ts
import { HttpError } from "fresh";
import { HttpError } from "sweet";
async function authMiddleware(ctx) {
const user = ctx.state.user;
@@ -106,7 +106,7 @@ When an `HttpError` is thrown, Fresh catches it and invokes the error handler.
You can check the status code in your error handler:
```ts
import { HttpError } from "fresh";
import { HttpError } from "sweet";
app.onError("*", (ctx) => {
if (ctx.error instanceof HttpError) {
+2 -2
View File
@@ -44,7 +44,7 @@ For more complex scenarios, or to set page metadata from
[islands](/docs/concepts/islands), Fresh ships with the `<Head>`-component.
```tsx routes/about.tsx
import { Head } from "fresh/runtime";
import { Head } from "sweet/runtime";
export default define.page((ctx) => {
return (
@@ -66,7 +66,7 @@ component state changes, the document head is updated automatically:
```tsx islands/MetaUpdater.tsx
import { useState } from "preact/hooks";
import { Head } from "fresh/runtime";
import { Head } from "sweet/runtime";
export default function MetaUpdater() {
const [title, setTitle] = useState("Welcome");
+2 -2
View File
@@ -19,7 +19,7 @@ The quickest way to get started is to enable partials for every page in
```diff routes/_app.tsx
import { define } from "../utils.ts";
+ import { Partial } from "fresh/runtime";
+ import { Partial } from "sweet/runtime";
export default define.page(function App({ Component }) {
return (
@@ -105,7 +105,7 @@ the sidebar might look like this respectively.
```tsx routes/partials/docs/[id].tsx
import { define } from "../utils.ts";
import { Partial } from "fresh/runtime";
import { Partial } from "sweet/runtime";
// We only want to render the content, so disable
// the `_app.tsx` template as well as any potentially
+3 -3
View File
@@ -32,9 +32,9 @@ command.
## Update Fresh
The easiest way to resolve most issues is to ensure that you're on the
[latest version](https://jsr.io/@fresh/core/versions) of Fresh. We continuously
work on Fresh and there is a good chance that the issue you're running into has
already been resolved in the latest version of Fresh.
[latest version](https://jsr.io/@paulaboks/sweet/versions) of Fresh. We
continuously work on Fresh and there is a good chance that the issue you're
running into has already been resolved in the latest version of Fresh.
## Don't use esm.sh
+13 -13
View File
@@ -14,7 +14,7 @@ The Fresh Vite plugin can be configured in `vite.config.ts`:
```ts vite.config.ts
import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
import { fresh } from "@paulaboks/sweet-vite";
export default defineConfig({
plugins: [
@@ -49,7 +49,7 @@ generally come first:
```ts vite.config.ts
import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
import { fresh } from "@paulaboks/sweet-vite";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
@@ -109,10 +109,10 @@ types so HMR and asset imports type-check:
"start": "deno serve -A _fresh/server.js"
},
"imports": {
"fresh": "jsr:@fresh/core@^2",
"sweet": "jsr:@paulaboks/sweet@^2",
"preact": "npm:preact@^10",
"@preact/signals": "npm:@preact/signals@^2",
+ "@fresh/plugin-vite": "jsr:@fresh/plugin-vite@^1",
+ "@paulaboks/sweet-vite": "jsr:@paulaboks/sweet-vite@^1",
+ "vite": "npm:vite@^7",
+ "@types/babel__core": "npm:@types/babel__core@^7"
},
@@ -124,7 +124,7 @@ types so HMR and asset imports type-check:
}
```
If you were using `@fresh/plugin-tailwind` / `@fresh/plugin-tailwindcss-v3`,
If you were using `@paulaboks/sweet-tailwind` / `@fresh/plugin-tailwindcss-v3`,
remove those imports — Vite has a first-party Tailwind plugin (see step 4).
### 2. Replace `dev.ts` with `vite.config.ts`
@@ -133,7 +133,7 @@ Delete `dev.ts` and create a `vite.config.ts` at the project root:
```ts vite.config.ts
import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
import { fresh } from "@paulaboks/sweet-vite";
export default defineConfig({
plugins: [fresh()],
@@ -188,7 +188,7 @@ Replace the Builder-side Tailwind plugin with the official Vite plugin:
```diff deno.json
"imports": {
- "@fresh/plugin-tailwind": "jsr:@fresh/plugin-tailwind@^1",
- "@paulaboks/sweet-tailwind": "jsr:@paulaboks/sweet-tailwind@^1",
- "@tailwindcss/postcss": "npm:@tailwindcss/postcss@^4",
- "postcss": "npm:postcss@^8",
+ "@tailwindcss/vite": "npm:@tailwindcss/vite@^4",
@@ -198,7 +198,7 @@ Replace the Builder-side Tailwind plugin with the official Vite plugin:
```ts vite.config.ts
import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
import { fresh } from "@paulaboks/sweet-vite";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
@@ -229,13 +229,13 @@ change.
- [ ] `client.ts` created and imports your CSS
- [ ] Stylesheet moved out of `static/` and the `<link>` removed from `_app.tsx`
- [ ] `deno.json` tasks point at `vite` / `vite build`
- [ ] `@fresh/plugin-vite`, `vite`, and `@types/babel__core` in `imports`
- [ ] `@paulaboks/sweet-vite`, `vite`, and `@types/babel__core` in `imports`
- [ ] `"vite/client"` in `compilerOptions.types`
- [ ] Tailwind (if used) switched to `@tailwindcss/vite`
> [info]: If you get stuck, run `deno run -Ar jsr:@fresh/init` in a scratch
> directory and diff the generated project against yours — the generator is the
> source of truth for a working Vite-based Fresh setup.
> [info]: If you get stuck, run `deno run -Ar jsr:@paulaboks/sweet-init` in a
> scratch directory and diff the generated project against yours — the generator
> is the source of truth for a working Vite-based Fresh setup.
## Debugging
@@ -250,7 +250,7 @@ To inspect plugin transformations, use
```ts vite.config.ts
import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
import { fresh } from "@paulaboks/sweet-vite";
import inspect from "vite-plugin-inspect";
export default defineConfig({
+1 -1
View File
@@ -29,7 +29,7 @@ There are two main approaches depending on your use case.
The simplest way to add a WebSocket endpoint:
```ts main.ts
import { App } from "fresh";
import { App } from "sweet";
const app = new App()
.ws("/ws", {
+3 -3
View File
@@ -13,7 +13,7 @@ A handler fetches data and returns it with `page()`. The page component receives
it in `props.data`:
```tsx routes/projects/[id].tsx
import { HttpError, page } from "fresh";
import { HttpError, page } from "sweet";
import { define } from "@/utils.ts";
interface Data {
@@ -60,7 +60,7 @@ For simpler cases, you can fetch data directly in an async component without a
separate handler:
```tsx routes/projects/[id].tsx
import { HttpError } from "fresh";
import { HttpError } from "sweet";
import { define } from "@/utils.ts";
export default define.page(async (ctx) => {
@@ -97,7 +97,7 @@ export default define.middleware(async (ctx) => {
```
```tsx routes/dashboard.tsx
import { page } from "fresh";
import { page } from "sweet";
import { define } from "@/utils.ts";
export const handler = define.handlers({
+2 -2
View File
@@ -11,7 +11,7 @@ in `vite.config.ts`). When you add a new file there, it will register a new
route automatically.
```ts main.ts
import { App, staticFiles } from "fresh";
import { App, staticFiles } from "sweet";
const app = new App({ basePath: "/foo" })
.use(staticFiles())
@@ -85,7 +85,7 @@ A custom [URL pattern][urlpattern] can be specified in the route configuration.
This pattern will be used instead of the file path based pattern:
```ts routes/my-route.ts
import { RouteConfig } from "fresh";
import { RouteConfig } from "sweet";
export const config: RouteConfig = {
routeOverride: "/x/:module@:version/:path*",
+5 -5
View File
@@ -29,7 +29,7 @@ An island can be used anywhere like a regular Preact component. Fresh will take
care of making it interactive on the client.
```tsx main.tsx
import { App, staticFiles } from "fresh";
import { App, staticFiles } from "sweet";
import MyIsland from "./islands/my-island.tsx";
const app = new App()
@@ -77,7 +77,7 @@ A powerful feature of Fresh is that you can pass server-rendered JSX to an
island via props.
```tsx routes/index.tsx
import { staticFiles } from "fresh";
import { staticFiles } from "sweet";
import MyIsland from "../islands/my-island.tsx";
const app = new App()
@@ -126,7 +126,7 @@ constant from `fresh/runtime` to guard browser-only code. It is `false` on the
server and `true` in the browser:
```tsx islands/my-island.tsx
import { IS_BROWSER } from "fresh/runtime";
import { IS_BROWSER } from "sweet/runtime";
export function MyIsland() {
// Return any prerenderable JSX here which makes sense for your island
@@ -150,7 +150,7 @@ Use an island to register and render custom elements:
```tsx islands/MyElement.tsx
import { useEffect } from "preact/hooks";
import { IS_BROWSER } from "fresh/runtime";
import { IS_BROWSER } from "sweet/runtime";
export function MyElement() {
useEffect(() => {
@@ -182,7 +182,7 @@ inside an island:
```tsx islands/ThirdPartyElement.tsx
import { useEffect } from "preact/hooks";
import { IS_BROWSER } from "fresh/runtime";
import { IS_BROWSER } from "sweet/runtime";
export function ShoelaceButton() {
useEffect(() => {
+2 -2
View File
@@ -103,7 +103,7 @@ full-screen dashboard, or a print view. Use `skipInheritedLayouts` in the route
config to skip all layouts inherited from parent directories:
```tsx routes/login.tsx
import { type RouteConfig } from "fresh";
import { type RouteConfig } from "sweet";
import { define } from "../utils.ts";
export const config: RouteConfig = {
@@ -128,7 +128,7 @@ You can also skip inherited layouts from within a layout file itself. This is
useful when a section of your site needs a completely different shell:
```tsx routes/admin/_layout.tsx
import { type LayoutConfig } from "fresh";
import { type LayoutConfig } from "sweet";
import { define } from "../../utils.ts";
export const config: LayoutConfig = {
+1 -1
View File
@@ -7,7 +7,7 @@ Routing defines which middlewares and routes should respond to a particular
request.
```ts main.ts
import { App } from "fresh";
import { App } from "sweet";
const app = new App()
.get("/", () => new Response("hello")) // Responds to: GET /
+5 -5
View File
@@ -10,7 +10,7 @@ disk for optimal performance with
headers.
```ts main.ts
import { staticFiles } from "fresh";
import { staticFiles } from "sweet";
const app = new App()
.use(staticFiles());
@@ -55,7 +55,7 @@ first directory in the array takes precedence.
```ts vite.config.ts
import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
import { fresh } from "@paulaboks/sweet-vite";
export default defineConfig({
plugins: [
@@ -99,7 +99,7 @@ Use the `asset()` function to add caching headers manually. It will be served
with a cache lifetime of one year.
```tsx routes/about.tsx
import { asset } from "fresh/runtime";
import { asset } from "sweet/runtime";
export default function About() {
// Adding caching headers manually
@@ -110,7 +110,7 @@ export default function About() {
For `<img>` tags with a `srcset` attribute, use `assetSrcSet()`:
```tsx routes/gallery.tsx
import { assetSrcSet } from "fresh/runtime";
import { assetSrcSet } from "sweet/runtime";
export default function Gallery() {
return (
@@ -139,7 +139,7 @@ deno add -D npm:vite-imagetools
```ts vite.config.ts
import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
import { fresh } from "@paulaboks/sweet-vite";
import { imagetools } from "vite-imagetools";
export default defineConfig({
+6 -5
View File
@@ -7,8 +7,9 @@ description: |
Fresh is organized as a monorepo with multiple packages:
- **`packages/fresh/`** - Core Fresh framework (`@fresh/core`)
- **`packages/plugin-vite/`** - Vite integration plugin (`@fresh/plugin-vite`)
- **`packages/fresh/`** - Core Fresh framework (`@paulaboks/sweet`)
- **`packages/plugin-vite/`** - Vite integration plugin
(`@paulaboks/sweet-vite`)
- **`packages/plugin-tailwindcss/`** - Tailwind CSS v4 plugin
- **`packages/plugin-tailwindcss-v3/`** - Tailwind CSS v3 plugin
- **`packages/init/`** - Project scaffolding tool
@@ -31,7 +32,7 @@ Run it before submitting any pull request.
The repository uses Deno
[workspaces](https://docs.deno.com/runtime/fundamentals/workspaces/) so all
packages in `packages/` are automatically available to each other using their
published names (`@fresh/core`, `@fresh/plugin-vite`, etc.).
published names (`@paulaboks/sweet`, `@paulaboks/sweet-vite`, etc.).
## Development
@@ -56,8 +57,8 @@ the project's `deno.json`:
```json deno.json
{
"imports": {
"@fresh/core": "jsr:@fresh/core@^2.0.0",
"@fresh/plugin-vite": "jsr:@fresh/plugin-vite@^1.0.0"
"@paulaboks/sweet": "jsr:@paulaboks/sweet@^2.0.0",
"@paulaboks/sweet-vite": "jsr:@paulaboks/sweet-vite@^1.0.0"
},
"links": [
"../path/to/fresh/packages/fresh",
+1 -1
View File
@@ -10,7 +10,7 @@ Deploy Fresh to Cloudflare Workers by following these instructions:
```diff vite.config.ts
import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
import { fresh } from "@paulaboks/sweet-vite";
+ import { cloudflare } from "@cloudflare/vite-plugin";
export default defineConfig({
+3 -3
View File
@@ -55,7 +55,7 @@ export default define.middleware((ctx) => {
Return different formats based on the `Accept` header:
```ts routes/api/users/[id].ts
import { HttpError } from "fresh";
import { HttpError } from "sweet";
import { define } from "@/utils.ts";
export const handler = define.handlers({
@@ -110,7 +110,7 @@ session example.
Access URL search params from the context:
```ts routes/search.tsx
import { page } from "fresh";
import { page } from "sweet";
import { define } from "@/utils.ts";
export const handler = define.handlers({
@@ -141,7 +141,7 @@ export default define.middleware(async (ctx) => {
Or set headers on a specific route using `page()`:
```ts
import { page } from "fresh";
import { page } from "sweet";
return page(data, {
headers: { "Cache-Control": "public, max-age=3600" },
+1 -1
View File
@@ -9,7 +9,7 @@ Let's set up your first Fresh project. To create a new project, run this
command:
```sh Terminal
deno run -Ar jsr:@fresh/init
deno run -Ar jsr:@paulaboks/sweet-init
```
This will spawn a short wizard that guides you through the setup, like the
+2 -2
View File
@@ -10,7 +10,7 @@ Standards. It's designed for building high-quality, performant, and personalized
web applications.
```tsx main.ts
import { App } from "fresh";
import { App } from "sweet";
const app = new App()
.get("/", () => new Response("hello world"))
@@ -24,7 +24,7 @@ app.listen();
Create a new Fresh app by running:
```sh Terminal
deno run -Ar jsr:@fresh/init
deno run -Ar jsr:@paulaboks/sweet-init
```
## Features
+8 -7
View File
@@ -50,7 +50,7 @@ Fresh configuration to the [fresh vite plugin](/docs/advanced/vite).
```ts vite.config.ts
import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
import { fresh } from "@paulaboks/sweet-vite";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
@@ -86,7 +86,7 @@ Similarly, configuration related to running Fresh in production can be passed to
`new App()`:
```ts main.ts
import { App, staticFiles } from "fresh";
import { App, staticFiles } from "sweet";
export const app = new App()
// Add static file serving middleware
@@ -158,11 +158,11 @@ accordingly.
## Update imports
Add `jsr:@fresh/plugin-vite` and `npm:vite` to `imports` in your `deno.json`
Add `jsr:@paulaboks/sweet-vite` and `npm:vite` to `imports` in your `deno.json`
file, either manually or with this command:
```shell
deno install npm:vite jsr:@fresh/plugin-vite
deno install npm:vite jsr:@paulaboks/sweet-vite
```
This should be enough in most cases. If you still encounter problems, you may
@@ -188,8 +188,8 @@ you can add if needed. This middleware can be used to ensure that URLs always
have a trailing slash at the end or that they will never have one.
```diff main.ts
- import { App, staticFiles } from "fresh";
+ import { App, staticFiles, trailingSlashes } from "fresh";
- import { App, staticFiles } from "sweet";
+ import { App, staticFiles, trailingSlashes } from "sweet";
export const app = new App({ root: import.meta.url })
.use(staticFiles())
@@ -314,7 +314,8 @@ to [update the command](/docs/deployment/deno-compile) to generate the binary.
If you run into problems with upgrading your app, first, try starting a new
Fresh 2 project and looking at the new structure.
eg. `mkdir fresh2-demo && cd fresh2-demo && deno run -Ar jsr:@fresh/init`
eg.
`mkdir fresh2-demo && cd fresh2-demo && deno run -Ar jsr:@paulaboks/sweet-init`
### 2. Document
+2 -2
View File
@@ -8,7 +8,7 @@ to HTTP requests. These allow the server to indicate which origins (domains,
scheme or port) other than its own is permitted to load resources from.
```ts main.ts
import { cors } from "fresh";
import { cors } from "sweet";
const app = new App()
.use(cors({
@@ -24,5 +24,5 @@ const app = new App()
## Options
See the [API docs](https://jsr.io/@fresh/core/doc/~/cors) for a list of all
See the [API docs](https://jsr.io/@paulaboks/sweet/doc/~/cors) for a list of all
supported options
+3 -3
View File
@@ -7,7 +7,7 @@ The `csp()` middleware can be used to add
to HTTP requests. These restrict which resources a document is allowed to load.
```ts main.ts
import { csp } from "fresh";
import { csp } from "sweet";
const app = new App()
.use(csp({
@@ -32,7 +32,7 @@ This ensures only inline `<script>` and `<style>` tags rendered by Fresh are
allowed to execute.
```ts main.ts
import { csp } from "fresh";
import { csp } from "sweet";
const app = new App()
.use(csp({ useNonce: true }))
@@ -70,5 +70,5 @@ When `useNonce` is enabled:
## Options
See the [API docs](https://jsr.io/@fresh/core/doc/~/csp) for a list of all
See the [API docs](https://jsr.io/@paulaboks/sweet/doc/~/csp) for a list of all
supported options.
+1 -1
View File
@@ -12,7 +12,7 @@ and
headers. Requests from untrusted origins are rejected.
```ts main.ts
import { App, csrf } from "fresh";
import { App, csrf } from "sweet";
const app = new App();
+2 -2
View File
@@ -28,7 +28,7 @@ Since Fresh plugins are just middlewares and route handlers, creating a reusable
plugin is as simple as exporting a function that returns a middleware:
```ts plugins/request-id.ts
import type { MiddlewareFn } from "fresh";
import type { MiddlewareFn } from "sweet";
export function requestId(): MiddlewareFn<{ requestId: string }> {
return async (ctx) => {
@@ -41,7 +41,7 @@ export function requestId(): MiddlewareFn<{ requestId: string }> {
```
```ts main.ts
import { App, staticFiles } from "fresh";
import { App, staticFiles } from "sweet";
import { requestId } from "./plugins/request-id.ts";
const app = new App()
+5 -5
View File
@@ -7,7 +7,7 @@ It supports deny lists, allow lists, and CIDR subnet matching. Deny rules always
take precedence over allow rules.
```ts main.ts
import { App, ipFilter } from "fresh";
import { App, ipFilter } from "sweet";
const app = new App()
.use(ipFilter({
@@ -23,7 +23,7 @@ Block specific IPs or subnets. Any request from a matching address receives a
403 Forbidden response:
```ts main.ts
import { App, ipFilter } from "fresh";
import { App, ipFilter } from "sweet";
const app = new App()
.use(ipFilter({
@@ -37,7 +37,7 @@ When an allow list is provided, only matching IPs are permitted. All other
addresses are blocked:
```ts main.ts
import { App, ipFilter } from "fresh";
import { App, ipFilter } from "sweet";
const app = new App()
.use(ipFilter({
@@ -51,7 +51,7 @@ When both lists are provided, deny rules are checked first. An IP that appears
in both lists is blocked:
```ts main.ts
import { App, ipFilter } from "fresh";
import { App, ipFilter } from "sweet";
const app = new App()
.use(ipFilter({
@@ -68,7 +68,7 @@ By default, blocked requests receive a `403 Forbidden` response. Use the
`onBlocked` callback to customize this:
```ts main.ts
import { App, ipFilter } from "fresh";
import { App, ipFilter } from "sweet";
const app = new App()
.use(ipFilter({
+2 -2
View File
@@ -7,7 +7,7 @@ end with a slash character or will never end with one. It redirects the user's
request respectively.
```ts main.ts
import { trailingSlashes } from "fresh";
import { trailingSlashes } from "sweet";
const app = new App()
.use(trailingSlashes("never"))
@@ -17,7 +17,7 @@ const app = new App()
Always append a trailing slash:
```ts main.ts
import { trailingSlashes } from "fresh";
import { trailingSlashes } from "sweet";
const app = new App()
.use(trailingSlashes("always"))
+5 -5
View File
@@ -16,7 +16,7 @@ test assumes the `State` object in `utils.ts` has `text` property.
```ts tests/middleware.test.ts
import { expect } from "@std/expect";
import { App } from "fresh";
import { App } from "sweet";
import { define, type State } from "../utils.ts";
const middleware = define.middleware((ctx) => {
@@ -49,7 +49,7 @@ Both the [app wrapper](/docs/advanced/app-wrapper) component and
```tsx tests/appWrapper.test.tsx
import { expect } from "@std/expect";
import { App } from "fresh";
import { App } from "sweet";
import { define, type State } from "../utils.ts";
const AppWrapper = define.layout(function AppWrapper({ Component }) {
@@ -84,7 +84,7 @@ Same can be done for layouts.
```tsx tests/layout.test.tsx
import { expect } from "@std/expect";
import { App } from "fresh";
import { App } from "sweet";
import { define, type State } from "../utils.ts";
const MyLayout = define.layout(function MyLayout({ Component }) {
@@ -119,7 +119,7 @@ handler:
```ts tests/routes.test.ts
import { expect } from "@std/expect";
import { App } from "fresh";
import { App } from "sweet";
import { type State } from "../utils.ts";
// Import actual route handlers
@@ -150,7 +150,7 @@ to use JSX:
```tsx tests/island-ssr.test.tsx
import { expect } from "@std/expect";
import { App } from "fresh";
import { App } from "sweet";
import { useSignal } from "@preact/signals";
import { type State } from "../utils.ts";
import Counter from "../islands/Counter.tsx";