Skip to content
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

rename prerendering to building, remove config.kit.prerender.enabled #7762

Merged
merged 3 commits into from
Nov 23, 2022
Merged
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
5 changes: 5 additions & 0 deletions .changeset/silent-ducks-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[breaking] Rename `prerendering` to `building`, remove `config.kit.prerender.enabled`
2 changes: 2 additions & 0 deletions documentation/docs/20-core-concepts/40-page-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const prerender = 'auto';

The prerenderer will start at the root of your app and generate files for any prerenderable pages or `+server.js` routes it finds. Each page is scanned for `<a>` elements that point to other pages that are candidates for prerendering — because of this, you generally don't need to specify which pages should be accessed. If you _do_ need to specify which pages should be accessed by the prerenderer, you can do so with the `entries` option in the [prerender configuration](/docs/configuration#prerender).

While prerendering, the value of `building` imported from [`$app/environment`](/docs/modules#$app-environment) will be `true`.

#### Prerendering server routes

Unlike the other page options, `prerender` also applies to `+server.js` files. These files are _not_ affected from layouts, but will inherit default values from the pages that fetch data from them, if any. For example if a `+page.js` contains this `load` function...
Expand Down
2 changes: 0 additions & 2 deletions documentation/docs/50-api-reference/10-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ const config = {
prerender: {
concurrency: 1,
crawl: true,
enabled: true,
entries: ['*'],
handleHttpError: 'fail',
handleMissingId: 'fail',
Expand Down Expand Up @@ -253,7 +252,6 @@ See [Prerendering](/docs/page-options#prerender). An object containing zero or m

- `concurrency` — how many pages can be prerendered simultaneously. JS is single-threaded, but in cases where prerendering performance is network-bound (for example loading content from a remote CMS) this can speed things up by processing other tasks while waiting on the network response
- `crawl` — determines whether SvelteKit should find pages to prerender by following links from the seed page(s)
- `enabled` — set to `false` to disable prerendering altogether
- `entries` — an array of pages to prerender, or start crawling from (if `crawl: true`). The `*` string includes all non-dynamic routes (i.e. pages with no `[parameters]`, because SvelteKit doesn't know what value the parameters should have)
- `handleHttpError`

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const get_defaults = (prefix = '') => ({
crawl: true,
createIndexFiles: undefined,
default: undefined,
enabled: true,
enabled: undefined,
entries: ['*'],
force: undefined,
handleHttpError: 'fail',
Expand Down
5 changes: 4 additions & 1 deletion packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ const options = object(
(keypath) =>
`${keypath} has been removed. You can set it inside the top level +layout.js instead. See the PR for more information: https://github.com/sveltejs/kit/pull/6197`
),
enabled: boolean(true),
enabled: error(
(keypath) =>
`${keypath} has been removed. You can wrap any code that should not be executed during build in a \`if (!building) {...}\` block. See the discussion for more information: https://github.com/sveltejs/kit/discussions/7716`
),
entries: validate(['*'], (input, keypath) => {
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
throw new Error(`${keypath} must be an array of strings`);
Expand Down
7 changes: 1 addition & 6 deletions packages/kit/src/core/prerender/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ export async function prerender() {
/** @type {import('types').ValidatedKitConfig} */
const config = (await load_config()).kit;

if (!config.prerender.enabled) {
output_and_exit({ prerendered, prerender_map });
return;
}

/** @type {import('types').Logger} */
const log = logger({
verbose: verbose === 'true'
Expand Down Expand Up @@ -111,8 +106,8 @@ export async function prerender() {
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;

override({
building: true,
paths: config.paths,
prerendering: true,
read: (file) => readFileSync(join(config.files.assets, file))
});

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/exports/vite/build/build_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const server_template = ({ config, hooks, has_service_worker, runtime, template,
import root from '__GENERATED__/root.svelte';
import { respond } from '${runtime}/server/index.js';
import { set_paths, assets, base } from '${runtime}/paths.js';
import { set_prerendering, set_version } from '${runtime}/env.js';
import { set_building, set_version } from '${runtime}/env.js';
import { set_private_env } from '${runtime}/env-private.js';
import { set_public_env } from '${runtime}/env-public.js';

Expand All @@ -53,7 +53,7 @@ let default_protocol = 'https';
export function override(settings) {
default_protocol = settings.protocol || default_protocol;
set_paths(settings.paths);
set_prerendering(settings.prerendering);
set_building(settings.building);
read = settings.read;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function preview(vite, vite_config, svelte_config) {

override({
paths: { base, assets },
prerendering: false,
building: false,
protocol,
read: (file) => fs.readFileSync(join(svelte_config.kit.files.assets, file))
});
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/app/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const browser = !import.meta.env.SSR;
*/
export const dev = __SVELTEKIT_DEV__;

export { prerendering, version } from '../env.js';
export { building, version } from '../env.js';
6 changes: 3 additions & 3 deletions packages/kit/src/runtime/env.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export let prerendering = false;
export let building = false;
export let version = '';

/** @param {boolean} value */
export function set_prerendering(value) {
prerendering = value;
export function set_building(value) {
building = value;
}

/** @param {string} value */
Expand Down
10 changes: 5 additions & 5 deletions packages/kit/test/prerendering/basics/src/hooks.server.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { prerendering } from '$app/environment';
import { building } from '$app/environment';

const initial_prerendering = prerendering;
const initial_building = building;

/** @type {import('@sveltejs/kit').Handle} */
export const handle = async ({ event, resolve }) => {
if (event.url.pathname === '/prerendering-true' && prerendering) {
if (event.url.pathname === '/prerendering-true' && building) {
return await resolve(event, {
transformPageChunk: ({ html }) =>
html
.replace('__INITIAL_PRERENDERING__', String(initial_prerendering))
.replace('__PRERENDERING__', String(prerendering))
.replace('__INITIAL_PRERENDERING__', String(initial_building))
.replace('__PRERENDERING__', String(building))
});
}
return await resolve(event, {
Expand Down
21 changes: 0 additions & 21 deletions packages/kit/test/prerendering/fallback/package.json

This file was deleted.

11 changes: 0 additions & 11 deletions packages/kit/test/prerendering/fallback/src/app.html

This file was deleted.

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions packages/kit/test/prerendering/fallback/svelte.config.js

This file was deleted.

16 changes: 0 additions & 16 deletions packages/kit/test/prerendering/fallback/tsconfig.json

This file was deleted.

23 changes: 0 additions & 23 deletions packages/kit/test/prerendering/fallback/vite.config.js

This file was deleted.

12 changes: 6 additions & 6 deletions packages/kit/types/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ declare namespace App {

/**
* ```ts
* import { browser, dev, prerendering } from '$app/environment';
* import { browser, building, dev, version } from '$app/environment';
* ```
*/
declare module '$app/environment' {
Expand All @@ -77,17 +77,17 @@ declare module '$app/environment' {
export const browser: boolean;

/**
* Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
* SvelteKit analyses your app during the `build` step by running it. During this process, `building` is `true`. This also applies during prerendering.
*/
export const dev: boolean;
export const building: boolean;

/**
* `true` when prerendering, `false` otherwise.
* Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
*/
export const prerendering: boolean;
export const dev: boolean;

/**
* The value of `config.kit.version.name`
* The value of `config.kit.version.name`.
*/
export const version: string;
}
Expand Down
1 change: 0 additions & 1 deletion packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ export interface KitConfig {
concurrency?: number;
crawl?: boolean;
default?: boolean;
enabled?: boolean;
entries?: Array<'*' | `/${string}`>;
handleHttpError?: PrerenderHttpErrorHandlerValue;
handleMissingId?: PrerenderMissingIdHandlerValue;
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export interface ServerModule {
Server: typeof InternalServer;

override(options: {
building: boolean;
paths: {
base: string;
assets: string;
};
prerendering: boolean;
protocol?: 'http' | 'https';
read(file: string): Buffer;
}): void;
Expand Down