Only avaiable in Vite projects, not in Webpack

The postBuild hook is called just before Keycloakify bundles the themes resources into the jar.

This gives you the ability to implement some custom transformation.

Let's say, for example, we have a big material-icons in our public directory and thoses icons are used in the main app but not in the Keycloak theme. We can use the postBuild hook to make sure that thoses icons are not bundled in the generated jar files.

import * as fs from "fs/promises";
import * as path from "path";

export default defineConfig({
    plugins: [
            postBuild: async (buildContext) => {
                await fs.rm(
                        buildContext.themeNames[0], // keycloakify-starter
                        "login", // Note: We assume we only have an login theme, if we had an account theme we would have to remove it there as well.
                        "dist", // Your Vite dist/ or Webpack build/ is here.
                    { recursive: true }

When this function is invoked the current working directory (process.cwd()) is the root of the directory of the files about to be archived.

You can get an idea of how is structured the files inside the jar by extracting it manually:

mkdir dist_keycloak/extracted
cd dist_keycloak/extracted
jar -xf ../keycloak-theme-for-kc-25-and-above.jar

Last updated