Pour utiliser SvelteKit comme un générateur de site statique (SSG), utilisez
adapter-static.
Cet adaptateur va pré-rendre tout votre site comme une collection de fichiers statiques. Si vous
souhaitez pré-rendre uniquement certaines pages et rendre dynamiquement sur le serveur d’autres
pages, vous aurez besoin d’un adaptateur différent combiné à l’usage de l’option
prerender.
As well as SvelteKit, the plugin options are used by other tooling that integrates with Svelte such as editor extensions.
Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte, so you can set options like inspector here too. The experimental namespace is shared — SvelteKit reads its own flags and forwards the rest.
Legacy mode
Prior to SvelteKit 3, config lived in a svelte.config.js file, which is no longer supported. The ability to configure SvelteKit via vite.config.js was added in version 2.62.
Type helper to make it easier to use vite.config.ts
accepts a direct
{@link
UserConfig
}
object, or a function that returns it.
The function receives a
{@link
ConfigEnv
}
object.
Type helper to make it easier to use vite.config.ts
accepts a direct
{@link
UserConfig
}
object, or a function that returns it.
The function receives a
{@link
ConfigEnv
}
object.
As well as SvelteKit, the plugin options are used by other tooling that integrates with Svelte such as editor extensions.
Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte, so you can set options like inspector here too. The experimental namespace is shared — SvelteKit reads its own flags and forwards the rest.
Legacy mode
Prior to SvelteKit 3, config lived in a svelte.config.js file, which is no longer supported. The ability to configure SvelteKit via vite.config.js was added in version 2.62.
Your adapter is run when executing vite build. It determines how the output is converted for different platforms.
undefined
:adapterimportadapter({ // les options par défaut sont montrées. Sur certaines
// plateformes, ces options sont définies automatiquement
// — voir plus bas
pages(property)pages:string:'build',assets(property)assets:string:'build',fallback(property)fallback:undefined:undefinedvarundefined,precompress(property)precompress:boolean:false,strict(property)strict:boolean:true})})]});
... et ajoutez l’option prerender à votre layout racine :
src/routes/+layout
// Si vous utilisez un fallback (c-à-d le mode SPA) vous n'avez pas besoin de pré-rendre toutes
// les pages en définissant ce paramètre, mais vous devriez pré-rendre un maximum de pages pour
// éviter des impacts significatifs sur les performances ou le référencement de votre applicationexportconstprerenderconstprerender:true=true;
Vous devez vous assurer que l’option de SvelteKit
trailingSlash est définie de manière appropriée à votre
environnement. Si votre hôte n’affiche pas /a.html à la réception d’une requête pour /a, vous
devrez alors définir trailingSlash: 'always' dans votre layout racine pour créer plutôt
/a/index.html.
Vous devez vous assurer que l’option ssr de SvelteKit n’est pas
définie à false. Autrement, le pré-rendu ne construira qu’une page “coquille” vide au lieu de la
page entièrement rendue.
Support zéro configuration
Certaines plateformes ont un support ne nécessitant pas de configuration (et d’autres viendront dans
le futur) :
As well as SvelteKit, the plugin options are used by other tooling that integrates with Svelte such as editor extensions.
Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte, so you can set options like inspector here too. The experimental namespace is shared — SvelteKit reads its own flags and forwards the rest.
Legacy mode
Prior to SvelteKit 3, config lived in a svelte.config.js file, which is no longer supported. The ability to configure SvelteKit via vite.config.js was added in version 2.62.
Type helper to make it easier to use vite.config.ts
accepts a direct
{@link
UserConfig
}
object, or a function that returns it.
The function receives a
{@link
ConfigEnv
}
object.
Type helper to make it easier to use vite.config.ts
accepts a direct
{@link
UserConfig
}
object, or a function that returns it.
The function receives a
{@link
ConfigEnv
}
object.
As well as SvelteKit, the plugin options are used by other tooling that integrates with Svelte such as editor extensions.
Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte, so you can set options like inspector here too. The experimental namespace is shared — SvelteKit reads its own flags and forwards the rest.
Legacy mode
Prior to SvelteKit 3, config lived in a svelte.config.js file, which is no longer supported. The ability to configure SvelteKit via vite.config.js was added in version 2.62.
Your adapter is run when executing vite build. It determines how the output is converted for different platforms.
undefined
:adapterimportadapter({...})})]});
Options
pages
Le dossier dans lequel écrire les pages pré-rendues. Vaut par défaut build.
assets
Le dossier dans lequel écrire les assets statiques (le contenu de static, plus les fichiers JS et
CSS client générés par SvelteKit). En général cette option devrait être le même que pages, et va
donc valoir par défaut la valeur de pages, mais dans de rares circonstances vous pourriez avoir
besoin de définir vos pages et vos assets dans des endroits différents.
fallback
Pour créer une SPA, vous devez préciser le nom de la page de secours que
SvelteKit va générer, qui peut être utilisé comme point d’entrée pour les URLs qui n’ont pas été
générées. C’est en général 200.html, mais peut varier en fonction de votre plate-forme de
déploiement. Vous devriez éviter index.html lorsque c’est possible pour éviter de rentrer en
conflit avec une éventuelle page d’accueil pré-rendue.
Cette option a un impact significatif sur les performances et le référencement de votre
application. Elle n’est recommandée que dans certaines circonstances telles que l’embarquement du
site dans une application mobile. Voir la section sur les SPA pour plus de
détails et en apprendre plus sur les alternatives.
precompress
Si true, pré-compresse les fichiers avec brotli et gzip. Cela va ainsi générer des fichiers .br
et .gz.
strict
Par défaut, l’adaptateur adapter-static vérifie que soit toutes les pages et endpoints (s’il y en
a) de votre application ont été pré-rendues, ou si vous avez l’option fallback définie. Cette
vérification existe pour vous empêcher de publier accidentellement une application dont certaines
parties sont inaccessibles car non incluses dans le dossier compilé. Si vous savez que cette
situation n’est pas un problème pour vous (par exemple lorsqu’une certaine page n’existe que dans
certaines conditions), vous pouvez définir strict à false pour désactiver cette vérification.
GitHub Pages
Lorsque vous compilez pour GitHub
Pages, si le
nom de votre repo n’est pas équivalent à votre-nom.github.io, assurez-vous de mettre à jour
l’option config.paths.base pour que cela corresponde au nom de votre
repo. C’est nécessaire car votre site sera servi depuis
https://your-username.github.io/your-repo-name plutôt que depuis la racine.
Vous allez également avoir besoin de générer une page 404.html de secours pour remplacer la page
404 montrée par défaut par Github Pages.
Voici une configuration possible pour Github Pages :
As well as SvelteKit, the plugin options are used by other tooling that integrates with Svelte such as editor extensions.
Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte, so you can set options like inspector here too. The experimental namespace is shared — SvelteKit reads its own flags and forwards the rest.
Legacy mode
Prior to SvelteKit 3, config lived in a svelte.config.js file, which is no longer supported. The ability to configure SvelteKit via vite.config.js was added in version 2.62.
Type helper to make it easier to use vite.config.ts
accepts a direct
{@link
UserConfig
}
object, or a function that returns it.
The function receives a
{@link
ConfigEnv
}
object.
Type helper to make it easier to use vite.config.ts
accepts a direct
{@link
UserConfig
}
object, or a function that returns it.
The function receives a
{@link
ConfigEnv
}
object.
As well as SvelteKit, the plugin options are used by other tooling that integrates with Svelte such as editor extensions.
Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte, so you can set options like inspector here too. The experimental namespace is shared — SvelteKit reads its own flags and forwards the rest.
Legacy mode
Prior to SvelteKit 3, config lived in a svelte.config.js file, which is no longer supported. The ability to configure SvelteKit via vite.config.js was added in version 2.62.
A root-relative path that must start, but not end with / (e.g. /base-path), unless it is the empty string. This specifies where your app is served from and allows the app to live on a non-root path. Note that you need to prepend all your root-relative links with the base value or they will point to the root of your domain, not your base (this is how the browser works). You can use resolve(...) from $app/paths for that: <a href="{resolve('/your-page')}">Link</a>. If you find yourself writing this often, it may make sense to extract this into a reusable component.
The process.argv property returns an array containing the command-line
arguments passed when the Node.js process was launched. The first element will
be
{@link
execPath
}
. See process.argv0 if access to the original value
of argv[0] is needed. The second element will be the path to the JavaScript
file being executed. If a program entry point was provided, the second element
will be the absolute path to it. The remaining elements are additional command-line
arguments.
For example, assuming the following script for process-args.js:
It is possible to modify this object, but such modifications will not be
reflected outside the Node.js process, or (unless explicitly requested)
to other Worker threads.
In other words, the following example would not work:
Assigning a property on process.env will implicitly convert the value
to a string. This behavior is deprecated. Future versions of Node.js may
throw an error when the value is not a string, number, or boolean.
Unless explicitly specified when creating a Worker instance,
each Worker thread has its own copy of process.env, based on its
parent thread's process.env, or whatever was specified as the env option
to the Worker constructor. Changes to process.env will not be visible
across Worker threads, and only the main thread can make changes that
are visible to the operating system or to native add-ons. On Windows, a copy of process.env on a Worker instance operates in a case-sensitive manner
unlike the main thread.
v0.1.27
.BASE_PATHstring|undefined},})]});
Vous pouvez utiliser les actions Github pour déployer automatiquement votre site sur Github Pages
lorsque vous faites un changement. Voici un workflow d’exemple :
.github/workflows/deploy
name:DéploiementsurGitHubPageson:push:branches:'main'permissions:contents:readpages:readconcurrency:group:pagescancel-in-progress:falsejobs:build_site:runs-on:ubuntu-lateststeps:-name:Checkoutuses:actions/checkout@v7# Si vous utilisez pnpm, ajoutez cette étape puis changez les commandes et les clés de cache# plus bas pour utiliser pnpm# - name: Install pnpm# uses: pnpm/action-setup@v6-name:InstallNode.jsuses:actions/setup-node@v7with:node-version:24cache:npm-name:Installerlesdépendancesrun:npmi-name:ConfigurePagesid:pagesuses:actions/configure-pages@v6-name:buildenv:BASE_PATH:${{steps.pages.outputs.base_path}}run:|npm run build-name:UploadArtifactsuses:actions/upload-pages-artifact@v5with:# ceci devrait correspondre à l'option `pages` dans les options de l'adaptateur# adapter-staticpath:'build/'# garde les dotfiles comme `static/.well-known`include-hidden-files:truedeploy:needs:build_siteruns-on:ubuntu-latestpermissions:pages:writeid-token:writeenvironment:name:github-pagesurl:${{steps.deployment.outputs.page_url}}steps:-name:Deployid:deploymentuses:actions/deploy-pages@v5
Si vous n’utilisez pas d’action Github pour déployer votre site (par exemple, vous envoyez le site
compilé vers son propre repo), ajoutez un fichier .nojekyll vide dans votre dossier static pour
empêcher Jekyll d’interférer.