This is not recommended, Keycloakify or not, whenever possible prefer importing your assets using the import statement. Learn more.
src/login/Template.tsx
// Note: Base url is often just "/" but please use the BASE_URL env// as it enable Keycloakify to resolve your assets when in Keycloak. <imgsrc={`${import.meta.env.BASE_URL}foo.png`} />
This is how you would reliably import assets that you have in your public directory regardless of if you are in a Keycloak context or not.
Let's assume you have foo.png in the public/ directory. To import it you would do.
This is not recommended, Keycloakify or not, whenever possible prefer importing your assets using the import statement. Learn more.
src/login/Template.tsx
// This is like process.env.PUBLIC_URL but it works both inside// and outside of Keycloak. import { PUBLIC_URL } from"keycloakify/PUBLIC_URL";<imgsrc={`${PUBLIC_URL}/foo.png`} />
Importing Fonts
So, this is typically how you would import self hosted font in a Regular React App.
Let's imagine you have the following font index CSS file:
<!-- 🛑 This do not work in keycloakfy --><linkrel="stylesheet"href="/font.css" />
Unfortunately this approach does not work in Keycloakify.
The workaround consist in including all your @font-face statements directly in your public/index.html file.
This is how you would update your index.html file in order to make it work with Keycloakify:
<!-- 🛑 This do not work in keycloakfy --><linkrel="stylesheet"href="%PUBLIC_URL%/font.css" />
Unfortunately this approach does not work in Keycloakify.
The workaround consist in including all your @font-face statements directly in your public/index.html file.
This is how you would update your index.html file in order to make it work with Keycloakify:
Storybook: To have your font applied in your Storybook as well you need to import them as shown here.
Works out of the box ✅
Importing Default Keycloak Theme Resources
This section is mainly for transparency.
You should use your own assets instead of importing the default ones; that's the whole point of creating a custom theme.
To import resources available in the default theme, you can construct URLs like:
You can see what assets are available under public/keycloak-resources/login/resources.
If you want to choose which version of the assets to use, refer to this build option.
By default, the default CSS assets are imported and applied here in the login theme.