Skip to content

Commit 37ce4c8

Browse files
Option to pre-render the dynamic routes
1 parent 6335eff commit 37ce4c8

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

packages/kit/src/core/adapt/prerender.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
236236
for (const entry of build_data.entries) {
237237
await visit(entry, null);
238238
}
239+
} else if (entry === '**') {
240+
for (const route of build_data.dynamic_routes) {
241+
const svelte_path = route.a[route.a.length - 1];
242+
const match = svelte_path.match(/^src\/routes(.*)\.svelte$/);
243+
await visit(match[1], null);
244+
}
239245
} else {
240246
await visit(entry, null);
241247
}

packages/kit/src/core/adapt/test/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ suite('copy files', () => {
4040
};
4141

4242
/** @type {import('types/internal').BuildData} */
43-
const build_data = { client: [], server: [], static: [], entries: [] };
43+
const build_data = { client: [], server: [], static: [], entries: [], dynamic_routes: [] };
4444

4545
const utils = get_utils({ cwd, config, build_data, log });
4646

@@ -91,7 +91,13 @@ suite('prerender', async () => {
9191
};
9292

9393
/** @type {import('types/internal').BuildData} */
94-
const build_data = { client: [], server: [], static: [], entries: ['/nested'] };
94+
const build_data = {
95+
client: [],
96+
server: [],
97+
static: [],
98+
entries: ['/nested'],
99+
dynamic_routes: []
100+
};
95101

96102
const utils = get_utils({ cwd, config, build_data, log });
97103

packages/kit/src/core/build/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ export async function build(config, { cwd = process.cwd(), runtime = '@sveltejs/
7474
static: options.manifest.assets.map((asset) => posixify(asset.file)),
7575
entries: options.manifest.routes
7676
.map((route) => route.type === 'page' && route.path)
77-
.filter(Boolean)
77+
.filter(Boolean),
78+
// prettier-ignore
79+
/** @type import('types/internal').PageData[] */
80+
dynamic_routes: (options.manifest.routes.filter((route) => route.type === 'page' && !route.path))
7881
};
7982
}
8083

packages/kit/src/core/config/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const options = {
130130
}
131131

132132
option.forEach((page) => {
133-
if (page !== '*' && page[0] !== '/') {
133+
if (page !== '*' && page !== '**' && page[0] !== '/') {
134134
throw new Error(
135135
`Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
136136
);

packages/kit/types/internal.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export type BuildData = {
200200
server: string[];
201201
static: string[];
202202
entries: string[];
203+
dynamic_routes: PageData[];
203204
};
204205

205206
export type NormalizedLoadOutput = {

0 commit comments

Comments
 (0)