Vite
If you have a Vite project you can integrate Keycloakify directly inside it.
Svelte: Although this guide uses React as an example it's also applicable for Svelte, you just need to adapt it when relevent.
Let's assume we're working with a freshly initialized Vite project.


Let's start by installing Keycloakify (and optionally Storybook) to our project:
Next we want to move the relevant files from the starter template into our project:

Now you want to modify your entry point so that:
If the kcContext global is defined, render your Keycloakify theme
Else, reder your App as usual.
Let's say, for example, your src/main.tsx file currently looks like this:
You want to rename this file to src/main.app.tsx (for example) and modify it as follows:
Then you want to create the following src/main.tsx file, you can copy and paste the following code (it does not need to be adapted):
You also need to use Keycloakify's Vite plugin. Here we don't provide any build options but you probably at least want to define keycloakVersionTargets.
Finally you want to add to your package.json a script for building the theme and another one to start storybook.
Last setp is to exclude from your html <head /> things that aren't relevent in the context of Keycloak pages.
In the above example we tell Keycloakify not to include the <title> because Keycloakify will set it dynamically to something like "ACME- Login" or "ACME - Register".
We also exclude a placeholder script for injecting environnement variables at container startup.
That's it, your project is ready to go! 🎉
You can run npm run build-keycloak-theme, the JAR distribution of your Keycloak theme will be generated in dist\_keycloak.
You're now able to use all the Keycloakify commands (npx keycloakify --help) from the root of your project.
Last updated
Was this helpful?