|
1 | | -import { serverFunctions } from "@vinxi/server-functions/plugin"; |
2 | | -import { server as serverFunctionServer, serverTransform } from "@vinxi/server-functions/server"; |
| 1 | +import { createTanStackServerFnPlugin } from "@tanstack/server-functions-plugin"; |
3 | 2 | import defu from "defu"; |
4 | 3 | import { existsSync } from "node:fs"; |
5 | 4 | import { join } from "node:path"; |
@@ -38,6 +37,36 @@ function solidStartServerFsRouter(config) { |
38 | 37 | ); |
39 | 38 | } |
40 | 39 |
|
| 40 | +const SolidStartServerFnsPlugin = createTanStackServerFnPlugin({ |
| 41 | + // This is the ID that will be available to look up and import |
| 42 | + // our server function manifest and resolve its module |
| 43 | + manifestVirtualImportId: "solidstart:server-fn-manifest", |
| 44 | + client: { |
| 45 | + getRuntimeCode: () => |
| 46 | + `import { createServerReference } from "${normalize( |
| 47 | + fileURLToPath(new URL("../dist/runtime/server-runtime.js", import.meta.url)) |
| 48 | + )}"`, |
| 49 | + replacer: opts => |
| 50 | + `createServerReference(${() => {}}, '${opts.functionId}', '${opts.extractedFilename}')` |
| 51 | + }, |
| 52 | + ssr: { |
| 53 | + getRuntimeCode: () => |
| 54 | + `import { createServerReference } from '${normalize( |
| 55 | + fileURLToPath(new URL("../dist/runtime/server-fns-runtime.js", import.meta.url)) |
| 56 | + )}'`, |
| 57 | + replacer: opts => |
| 58 | + `createServerReference(${opts.fn}, '${opts.functionId}', '${opts.extractedFilename}')` |
| 59 | + }, |
| 60 | + server: { |
| 61 | + getRuntimeCode: () => |
| 62 | + `import { createServerReference } from '${normalize( |
| 63 | + fileURLToPath(new URL("../dist/runtime/server-fns-runtime.js", import.meta.url)) |
| 64 | + )}'`, |
| 65 | + replacer: opts => |
| 66 | + `createServerReference(${opts.fn}, '${opts.functionId}', '${opts.extractedFilename}')` |
| 67 | + } |
| 68 | +}); |
| 69 | + |
41 | 70 | export function defineConfig(baseConfig = {}) { |
42 | 71 | let { vite = {}, ...start } = baseConfig; |
43 | 72 | const extensions = [...DEFAULT_EXTENSIONS, ...(start.extensions || [])]; |
@@ -112,11 +141,7 @@ export function defineConfig(baseConfig = {}) { |
112 | 141 | } |
113 | 142 | }), |
114 | 143 | ...plugins, |
115 | | - serverTransform({ |
116 | | - runtime: normalize( |
117 | | - fileURLToPath(new URL("../dist/runtime/server-fns-runtime.js", import.meta.url)) |
118 | | - ) |
119 | | - }), |
| 144 | + SolidStartServerFnsPlugin.ssr, |
120 | 145 | start.experimental.islands ? serverComponents.server() : null, |
121 | 146 | solid({ ...start.solid, ssr: true, extensions: extensions.map(ext => `.${ext}`) }), |
122 | 147 | config("app-server", { |
@@ -177,11 +202,7 @@ export function defineConfig(baseConfig = {}) { |
177 | 202 | } |
178 | 203 | }), |
179 | 204 | ...plugins, |
180 | | - serverFunctions.client({ |
181 | | - runtime: normalize( |
182 | | - fileURLToPath(new URL("../dist/runtime/server-runtime.js", import.meta.url)) |
183 | | - ) |
184 | | - }), |
| 205 | + SolidStartServerFnsPlugin.client, |
185 | 206 | start.experimental.islands ? serverComponents.client() : null, |
186 | 207 | solid({ ...start.solid, ssr: start.ssr, extensions: extensions.map(ext => `.${ext}`) }), |
187 | 208 | config("app-client", { |
@@ -247,11 +268,7 @@ export function defineConfig(baseConfig = {}) { |
247 | 268 | cacheDir: "node_modules/.vinxi/server-fns" |
248 | 269 | }), |
249 | 270 | ...plugins, |
250 | | - serverFunctionServer({ |
251 | | - runtime: normalize( |
252 | | - fileURLToPath(new URL("../dist/runtime/server-fns-runtime.js", import.meta.url)) |
253 | | - ) |
254 | | - }), |
| 271 | + SolidStartServerFnsPlugin.server, |
255 | 272 | start.experimental.islands ? serverComponents.server() : null, |
256 | 273 | solid({ ...start.solid, ssr: true, extensions: extensions.map(ext => `.${ext}`) }), |
257 | 274 | config("app-server", { |
|
0 commit comments