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

Nx

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

Let's see how to integrate a Keycloakify theme into a Nx project with integrated monorepo.

In this example we'll start with the Nx Vite starter

npx create-nx-workspace@latest --preset=react-monorepo --bundler=vite

Next up we want to repatriate the Keycloakify Starter template sources. We only copy over the src and .storybook directory.

cd nx-monorepo
rm -rf apps/keycloak-theme/src
git clone https://github.com/keycloakify/keycloakify-starter tmp
mv tmp/src apps/keycloak-theme
mv tmp/.storybook apps/keycloak-theme
rm -rf tmp
package.json
{
  "name": "@nx-monorepo/source",
  "version": "0.0.0",
  "scripts": {
    "build-keycloak-theme": "nx build keycloak-theme && keycloakify build -p apps/keycloak-theme",
    "keycloak-theme-storybook": "npx storybook dev -p 6006 -c apps/keycloak-theme/.storybook",
    "start-keycloak": "keycloakify start-keycloak -p apps/keycloak-theme"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "tslib": "^2.3.0",
    "keycloakify": "^10.0.0"
  },
  "devDependencies": {
      "storybook": "^8.1.10",
      "@storybook/react": "^8.1.10",
      "@storybook/react-vite": "^8.1.10"
  // ...
npm install # or `pnpm install` or `yarn`...
apps/keycloak-theme/vite.config.ts
/// <reference types='vitest' />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { keycloakify } from "keycloakify/vite-plugin";

export default defineConfig({
  root: __dirname,
  cacheDir: '../../node_modules/.vite/apps/keycloak-theme',

  server: {
    port: 4200,
    host: 'localhost',
  },

  preview: {
    port: 4300,
    host: 'localhost',
  },

  plugins: [react(), nxViteTsPaths(), 
      keycloakify({
          themeName: "my-project",
          themeVersion: "1.0.0",
          keycloakifyBuildDirPath: '../../dist/apps/keycloak-theme'
       })
   ],

  // Uncomment this if you are using workers.
  // worker: {
  //  plugins: [ nxViteTsPaths() ],
  // },

  build: {
    outDir: 'dist',
    emptyOutDir: true,
    reportCompressedSize: true,
    commonjsOptions: {
      transformMixedEsModules: true,
    },
  },
});

Now if you run npm run build-keycloak-theme it will generate the JAR in dist/apps/keycloak-theme.

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

OR

  • 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 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
add-story
build options
keycloakVersionTargets
After moving src and .storybook to apps/keycloak-theme
the Quick Start Guide and fork the starter project.