Skip to content

Option to pre-render the dynamic routes #1870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/kit/src/core/adapt/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
for (const entry of build_data.entries) {
await visit(entry, null);
}
} else if (entry === '**') {
for (const route of build_data.dynamic_routes) {
const svelte_path = route.a[route.a.length - 1];
const match = svelte_path.match(/^src\/routes(.*)\.svelte$/);
await visit(match[1], null);
}
} else {
await visit(entry, null);
}
Expand Down
10 changes: 8 additions & 2 deletions packages/kit/src/core/adapt/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ suite('copy files', () => {
};

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

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

Expand Down Expand Up @@ -91,7 +91,13 @@ suite('prerender', async () => {
};

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

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

Expand Down
5 changes: 4 additions & 1 deletion packages/kit/src/core/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export async function build(config, { cwd = process.cwd(), runtime = '@sveltejs/
static: options.manifest.assets.map((asset) => posixify(asset.file)),
entries: options.manifest.routes
.map((route) => route.type === 'page' && route.path)
.filter(Boolean)
.filter(Boolean),
// prettier-ignore
/** @type import('types/internal').PageData[] */
dynamic_routes: (options.manifest.routes.filter((route) => route.type === 'page' && !route.path))
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const options = {
}

option.forEach((page) => {
if (page !== '*' && page[0] !== '/') {
if (page !== '*' && page !== '**' && page[0] !== '/') {
throw new Error(
`Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
);
Expand Down
1 change: 1 addition & 0 deletions packages/kit/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export type BuildData = {
server: string[];
static: string[];
entries: string[];
dynamic_routes: PageData[];
};

export type NormalizedLoadOutput = {
Expand Down