Keycloakify
HomeGitHubStorybookAlternative to keycloak-js
v11
  • Documentation
  • Release Notes & Upgrade Instructions
  • FAQ
v11
  • Quick Start
  • CSS Customization
  • Testing your Theme
    • Outside of Keycloak
    • Inside of Keycloak
  • Deploying Your Theme
  • Integrating Keycloakify in your Codebase
    • Vite
    • Create-React-App / Webpack
    • yarn/npm/pnpm/bun Workspaces
    • Turborepo
    • Nx
    • Angular Workspace
  • Common Use Case Examples
    • Using a Component Library
    • Custom Fonts
    • Changing the background image
    • Adding your Logo
    • Using Tailwind
    • Dark Mode Persistence
  • Features
    • Internationalization and Translations
      • Basic principles
      • Previewing Your Pages in Different Languages
      • Adding New Translation Messages or Changing the Default Ones
      • Adding Support for Extra Languages
    • Theme Variants
    • Environment Variables
    • Styling a Custom Page Not Included in Base Keycloak
    • Integrating an Existing Theme into Your Keycloakify Project
    • Compiler Options
      • --project
      • keycloakVersionTargets
      • environmentVariables
      • themeName
      • startKeycloakOptions
      • themeVersion
      • accountThemeImplementation
      • postBuild
      • XDG_CACHE_HOME
      • kcContextExclusionsFtl
      • keycloakifyBuildDirPath
      • groupId
      • artifactId
      • Webpack specific options
        • projectBuildDirPath
        • staticDirPathInProjectBuildDirPath
        • publicDirPath
  • Page-Specific Guides
    • Registration Page
    • Terms and Conditions Page
  • Theme types
    • Differences Between Login Themes and Other Types of Themes
    • Account Theme
      • Single-Page
      • Multi-Page
    • Email Theme
    • Admin Theme
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Integrating Keycloakify in your Codebase

Turborepo

Last updated 2 months ago

Was this helpful?

If you're unsure what this section is about, this approach is NOT for you. Instead, follow

First you want to create a new subproject in your monorepo, just clone the starter template into apps/keycloak-theme.

cd my-turborepo
git clone https://github.com/keycloakify/keycloakify-starter apps/keycloak-theme
rm -rf apps/keycloak-theme/.git
rm -rf apps/keycloak-theme/.github

Change the name field in the package.json of your keycloakify sub app.

apps/keycloak-theme/package.json
 {
-    "name": "keycloakify-starter",
+    "name": "keycloak-theme",
 }

Give an actual name to your theme (as you want it to apprear )

apps/keycloak-theme/vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { keycloakify } from "keycloakify/vite-plugin";

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [react(), keycloakify({
        themeName: "my-app"
    })]
});

Then you want to add a new script for building your theme in your root package.json

package.json
{
  "name": "my-turborepo",
  "scripts": {
    "build": "turbo build",
    "dev": "turbo dev",
    "lint": "turbo lint",
    "format": "prettier --write \"**/*.{ts,tsx,md}\"",
    "build-keycloak-theme": "turbo run build-keycloak-theme --filter=keycloak-theme",
    "start-keycloak": "keycloakify start-keycloak -p apps/keycloak-theme"
  },
  // ...
}

Add a turborepo task

turbo.json
{
  "$schema": "https://turbo.build/schema.json",
  "tasks": {
    // ... Other tasks
    "build-keycloak-theme": {
        "outputs": [
            "dist/**", 
            "dist_keycloak/**"
        ]
    }
  }
}

You can now build your keycloak theme at the root of your monorepo by running

npm run build-keycloak-theme

Optionally, if you want to change the location of the directory where the jar for your theme are created you can do:

apps/keycloak-theme/vite.config.ts
export default defineConfig({
    plugins: [react(), keycloakify({
        themeName: "my-app",
        keycloakifyBuildDirPath: "../../dist/apps/keycloak-theme"
    })]
});
turbo.json
 {
   "$schema": "https://turbo.build/schema.json",
   "tasks": {
     // ... Other tasks
     "build-keycloak-theme": {
         "outputs": [
             "dist/**",
-            "dist_keycloak/**"
+            "../../dist/apps/keycloak-theme/**"
         ]
     }
   }
 }

If you applies those changes, when you'll run npm run build-keycloak-theme your JARs are going to be generated in dist/keycloak-theme/

  • cd apps/keycloak-theme && npx keycloakify add-story

  • npx keycloakify add-story -p apps/keycloak-theme from the root of your monorepo

When you want to use the keycloakify CLI commands you can either cd into your keycloakify sub app directory or use the . Like for example if you want to run add-story you can do either:

To go beyond the base configuration you might want to explore what are available. Starting with with keycloakVersionTargets to make sure that you only generates the JARs file you need.

--project option of the Keycloakify CLI
build options
keycloakVersionTargets
in the Keycloak Admin Console
Building the theme, only compiling for Keycloak 25 with a custom jar file name. Demonstrating the effectiveness of turborepo cache
the Quick Start Guide and fork the starter project.