postBuild

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.

vite.config.ts
import * as fs from "fs/promises";
import * as path from "path";

export default defineConfig({
    plugins: [
        react(),
        keycloakify({
            postBuild: async (buildContext) => {
                await fs.rm(
                    path.join(
                        "theme",
                        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.
                        "resources",
                        "dist", // Your Vite dist/ or Webpack build/ is here.
                        "material-icons"
                    ),
                    { 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