diff --git a/.changeset/frontends-option.md b/.changeset/frontends-option.md index 9e02462..e32ea47 100644 --- a/.changeset/frontends-option.md +++ b/.changeset/frontends-option.md @@ -1,5 +1,5 @@ --- -'@solidjs/vite-plugin': minor +'@solidjs/vite-plugin': patch --- Add a `frontends` option: other languages that lower to Solid can claim a file extension and compile its modules themselves (`frontends: { ".x": x() }`). A front end's `compile(source, { id, moduleId, ssr, root, solid, addWatchFile })` returns `{ code, map, css }`, given the compiler options this plugin would use for a JSX module in that environment; the result then takes the lowered `.tsrx` route (lazy and refresh passes, server functions keyed by the module's real path, `css` as a CSS module, dep scanning). Server functions in a front end's modules need `@solidjs/compiler` with secondary passes that accept any extension. `.rx` (ReactiveScript) is built in: with `@reactivescript/compiler` installed in the project, `.rx` modules compile with no option. diff --git a/README.md b/README.md index aa9507c..6174d3d 100644 --- a/README.md +++ b/README.md @@ -949,6 +949,30 @@ configureServerFunctionsServer({ Set `csrf: false` only when another trusted layer protects the endpoint. +Custom serialization (extra seroval plugins for class instances such as a +`Money` or an `ObjectId`) is configured the same way, once per side. Set the +server codec in the `configure` module and the client codec in +[`start.clientSetup`](#optionsstart), both from one shared options module: + +```ts +// src/serialization.ts +import type { JSONCodecOptions } from '@solidjs/web/serialization'; +export default { plugins: [MoneyPlugin] } satisfies JSONCodecOptions; + +// src/server-config.ts (serverFunctions.configure) +import { configureServerFunctionsServer } from '@solidjs/web/server-functions/server'; +import codec from './serialization'; +configureServerFunctionsServer({ codec }); + +// src/client-setup.ts (start.clientSetup) +import { configureServerFunctionsClient } from '@solidjs/web/server-functions/client'; +import codec from './serialization'; +configureServerFunctionsClient({ codec }); +``` + +Both sides must use the same plugins. This covers server-function arguments +and results; the SSR hydration payload takes its own `plugins` option. + Meta-frameworks that need to control plugin ordering and dispatch requests through their own server should use the standalone `serverFunctions()` export instead, which never installs the dev middleware. See