Skip to content

Commit

Permalink
update config to anticipate Vite updates, clearer experimental featur…
Browse files Browse the repository at this point in the history
…es, routesDir
  • Loading branch information
ryansolid committed Mar 6, 2024
1 parent e33d506 commit 28357e6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-jobs-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": minor
---

update config to anticipate Vite updates, clearer experimental features, routesDir
2 changes: 1 addition & 1 deletion app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { config } from "vinxi/plugins/config";
export default defineConfig({
appRoot: "./docs",
extensions: ["mdx", "md"],
islands: true,
experimental: { islands: true },
server: {
preset: "cloudflare_module",
rollupConfig: {
Expand Down
12 changes: 6 additions & 6 deletions docs/routes/api/app-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ export default defineConfig({
});
```

The `vite` option can also be a function which can be customized for each Vinxi Router. In SolidStart we use 3, `server` for SSR, `client` for the browser, and `server-function` for server functions.
The `vite` option can also be a function which can be customized for each Vinxi environment. In SolidStart we use 3, `server` for SSR, `client` for the browser, and `server-function` for server functions.

```tsx
import { defineConfig } from "@solidjs/start/config";

export default defineConfig({
vite({ router }) {
if (router === "server") {
} else if (router === "client") {
} else if (router === "server-function") {
vite({ enviroment }) {
if (enviroment === "server") {
} else if (enviroment === "client") {
} else if (enviroment === "server-function") {
}
return { plugins: [] };
}
Expand Down Expand Up @@ -122,4 +122,4 @@ The vite options are same as the default with exception of the `start` property
- `appRoot` (_string_, default `"./src"`): Sets the root of the application code.
- `routesDir` (_string_, default `"./routes"`): The path to where the routes are located.
- `ssr` (_boolean_ | "sync" | "async", default `true`): Providing a boolean value will toggle between client rendering and [streaming](https://docs.solidjs.com/references/concepts/ssr/streaming) server rendering (ssr) mode, while "sync" and "async" will render using Solid's [renderToString](https://docs.solidjs.com/references/concepts/ssr/simple-client-fetching-ssr) and [renderToStringAsync](https://docs.solidjs.com/references/concepts/ssr/async-ssr) respectively.
- `islands` (_boolean_, default `false`): _experimental_ toggles on "islands" mode.
- `experimental.islands` (_boolean_, default `false`): _experimental_ toggles on "islands" mode.
7 changes: 5 additions & 2 deletions packages/start/config/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ type SolidStartInlineConfig = {
extensions?: string[];
server?: AppOptions["server"];
appRoot?: string;
routeDir?: string;
middleware?: string;
islands?: boolean;
devOverlay?: boolean;
experimental?: {
islands?: boolean;
}
vite?:
| CustomizableConfig
| ((options: { router: "server" | "client" | "server-function" }) => CustomizableConfig);
| ((options: { environment: "server" | "client" | "server-function" }) => CustomizableConfig);
};

export declare function defineConfig(baseConfig?: SolidStartInlineConfig): any;
34 changes: 19 additions & 15 deletions packages/start/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ export function defineConfig(baseConfig = {}) {
const extensions = [...DEFAULT_EXTENSIONS, ...(start.extensions || [])];
start = defu(start, {
appRoot: "./src",
routeDir: "./routes",
ssr: true,
devOverlay: true,
islands: false,
experimental: {
islands: false
},
solid: {},
server: {
experimental: {
asyncContext: true
}
}
});
const routeDir = join(start.appRoot, start.routeDir);
let server = start.server;
if (!start.ssr) {
server = { ...server, prerender: { routes: ["/"] } };
Expand Down Expand Up @@ -79,15 +83,15 @@ export function defineConfig(baseConfig = {}) {
name: "ssr",
type: "http",
link: {
client: start.islands ? undefined : "client"
client: start.experimental.islands ? undefined : "client"
},
handler: `${start.appRoot}/entry-server${entryExtension}`,
middleware: start.middleware,
routes: solidStartServerFsRouter({ dir: `${start.appRoot}/routes`, extensions }),
routes: solidStartServerFsRouter({ dir: routeDir, extensions }),
extensions,
target: "server",
plugins: async () => {
const userConfig = typeof vite === "function" ? await vite({ router: "server" }) : { ...vite };
const userConfig = typeof vite === "function" ? await vite({ environment: "server" }) : { ...vite };
const plugins = userConfig.plugins || [];
delete userConfig.plugins;
return [
Expand All @@ -106,7 +110,7 @@ export function defineConfig(baseConfig = {}) {
serverTransform({
runtime: normalize(fileURLToPath(new URL("./server-fns-runtime.ts", import.meta.url)))
}),
start.islands ? serverComponents.server() : null,
start.experimental.islands ? serverComponents.server() : null,
solid({ ...start.solid, ssr: true, extensions: extensions.map(ext => `.${ext}`) }),
config("app-server", {
resolve: {
Expand All @@ -123,7 +127,7 @@ export function defineConfig(baseConfig = {}) {
},
cacheDir: "node_modules/.vinxi/server",
define: {
"import.meta.env.START_ISLANDS": JSON.stringify(start.islands),
"import.meta.env.START_ISLANDS": JSON.stringify(start.experimental.islands),
"import.meta.env.SSR": JSON.stringify(true),
"import.meta.env.START_SSR": JSON.stringify(start.ssr),
"import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay),
Expand All @@ -138,15 +142,15 @@ export function defineConfig(baseConfig = {}) {
type: "client",
base: "/_build",
handler: `${start.appRoot}/entry-client${entryExtension}`,
...(start.islands
...(start.experimental.islands
? {}
: {
routes: solidStartClientFsRouter({ dir: `${start.appRoot}/routes`, extensions })
routes: solidStartClientFsRouter({ dir: routeDir, extensions })
}),
extensions,
target: "browser",
plugins: async () => {
const userConfig = typeof vite === "function" ? await vite({ router: "client" }) : { ...vite };
const userConfig = typeof vite === "function" ? await vite({ environment: "client" }) : { ...vite };
const plugins = userConfig.plugins || [];
delete userConfig.plugins;
return [
Expand All @@ -165,14 +169,14 @@ export function defineConfig(baseConfig = {}) {
serverFunctions.client({
runtime: normalize(fileURLToPath(new URL("./server-runtime.ts", import.meta.url)))
}),
start.islands ? serverComponents.client() : null,
start.experimental.islands ? serverComponents.client() : null,
solid({ ...start.solid, ssr: start.ssr, extensions: extensions.map(ext => `.${ext}`) }),
config("app-client", {
resolve: {
alias: {
"#start/app": join(process.cwd(), start.appRoot, `app${entryExtension}`),
"~": join(process.cwd(), start.appRoot),
...(start.islands
...(start.experimental.islands
? {
"@solidjs/start/client": "@solidjs/start/client/islands"
}
Expand All @@ -187,7 +191,7 @@ export function defineConfig(baseConfig = {}) {
},
cacheDir: "node_modules/.vinxi/client",
define: {
"import.meta.env.START_ISLANDS": JSON.stringify(start.islands),
"import.meta.env.START_ISLANDS": JSON.stringify(start.experimental.islands),
"import.meta.env.SSR": JSON.stringify(false),
"import.meta.env.START_SSR": JSON.stringify(start.ssr),
"import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay),
Expand All @@ -206,9 +210,9 @@ export function defineConfig(baseConfig = {}) {
handler: normalize(fileURLToPath(new URL("./server-handler.ts", import.meta.url))),
middleware: start.middleware,
target: "server",
routes: solidStartServerFsRouter({ dir: `${start.appRoot}/routes`, extensions }),
routes: solidStartServerFsRouter({ dir: routeDir, extensions }),
plugins: async () => {
const userConfig = typeof vite === "function" ? await vite({ router: "server-function" }) : { ...vite };
const userConfig = typeof vite === "function" ? await vite({ environment: "server-function" }) : { ...vite };
const plugins = userConfig.plugins || [];
delete userConfig.plugins;
return [
Expand Down Expand Up @@ -243,7 +247,7 @@ export function defineConfig(baseConfig = {}) {
}
},
define: {
"import.meta.env.START_ISLANDS": JSON.stringify(start.islands),
"import.meta.env.START_ISLANDS": JSON.stringify(start.experimental.islands),
"import.meta.env.SSR": JSON.stringify(true),
"import.meta.env.START_SSR": JSON.stringify(start.ssr),
"import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay),
Expand Down
File renamed without changes.

0 comments on commit 28357e6

Please sign in to comment.