> For the complete documentation index, see [llms.txt](https://docs.keycloakify.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keycloakify.dev/keycloakify/v10/testing-your-theme/with-vite-or-webpack-in-dev-mode.md).

# With Vite or Webpack in dev mode

{% tabs %}
{% tab title="Vite" %}
{% hint style="info" %}
TLDR:

* Uncomment the `getKcContextMock()` in **src/main.tsx**
* **npm run dev**
* Don't forget to comment again when you're done testing.
  {% endhint %}
  {% endtab %}

{% tab title="Webpack" %}
{% hint style="info" %}
TLDR:

* Uncomment the `getKcContextMock()` in **src/index.tsx**
* **npm run start**
* Don't forget to comment again when you're done testing.
  {% endhint %}
  {% endtab %}
  {% endtabs %}

If you don't have Storybook in your project you can also test your theme with the dev server.

To do that, just uncomment some line in your entrypoint:

{% tabs %}
{% tab title="Vite" %}

<pre class="language-tsx" data-title="src/main.tsx"><code class="lang-tsx">import { createRoot } from "react-dom/client";
import { StrictMode, lazy, Suspense } from "react";

<strong>import { getKcContextMock } from "./login/KcPageStory";
</strong>
<strong>if (import.meta.env.DEV) {
</strong><strong>    window.kcContext = getKcContextMock({
</strong><strong>        pageId: "register.ftl",
</strong><strong>        overrides: {}
</strong><strong>    });
</strong><strong>}
</strong>
const KcLoginThemePage = lazy(() => import("./login/KcPage"));
const KcAccountThemePage = lazy(() => import("./account/KcPage"));

createRoot(document.getElementById("root")!).render(
    &#x3C;StrictMode>
        &#x3C;Suspense>
            {(() => {
                switch (window.kcContext?.themeType) {
                    case "login":
                        return &#x3C;KcLoginThemePage kcContext={window.kcContext} />;
                    case "account":
                        return &#x3C;KcAccountThemePage kcContext={window.kcContext} />;
                }
                return &#x3C;h1>No Keycloak Context&#x3C;/h1>;
            })()}
        &#x3C;/Suspense>
    &#x3C;/StrictMode>
);
</code></pre>

{% endtab %}

{% tab title="Webpack" %}

<pre class="language-tsx" data-title="src/index.tsx"><code class="lang-tsx">import { createRoot } from "react-dom/client";
import { StrictMode, lazy, Suspense } from "react";

<strong>import { getKcContextMock } from "./login/KcPageStory";
</strong>
<strong>if (process.env.NODE_ENV === "development") {
</strong><strong>    window.kcContext = getKcContextMock({
</strong><strong>        pageId: "register.ftl",
</strong><strong>        overrides: {}
</strong><strong>    });
</strong><strong>}
</strong>
const KcLoginThemePage = lazy(() => import("./login/KcPage"));
const KcAccountThemePage = lazy(() => import("./account/KcPage"));

createRoot(document.getElementById("root")!).render(
    &#x3C;StrictMode>
        &#x3C;Suspense>
            {(() => {
                switch (window.kcContext?.themeType) {
                    case "login":
                        return &#x3C;KcLoginThemePage kcContext={window.kcContext} />;
                    case "account":
                        return &#x3C;KcAccountThemePage kcContext={window.kcContext} />;
                }
                return &#x3C;h1>No Keycloak Context&#x3C;/h1>;
            })()}
        &#x3C;/Suspense>
    &#x3C;/StrictMode>
);
</code></pre>

{% endtab %}
{% endtabs %}

The pageId parameter of the getKcContextMock let you decide what page you want to test.\
The overrides parameter let you modify the the default kcContext mock for the page.\
\
For example you can set:

```tsx
window.kcContext = getKcContextMock({
  pageId: "login.ftl",
  overrides: {
    locale: {
      currentLanguageTag: "zh-CN",
    },
  },
});
```

For rendering the Login page in Chinese.

You can then run the development server with:

{% tabs %}
{% tab title="Vite" %}

```bash
npm run dev
```

{% endtab %}

{% tab title="Webpack (Create React App)" %}

```bash
npm run start
```

{% endtab %}
{% endtabs %}

<figure><img src="/files/xLWP0O8HAqzjVls5lKvY" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
When you're done testing, don't forget to comment back the import of the mock. Forgetting to do so will negatively impact the bundle size of your pages.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.keycloakify.dev/keycloakify/v10/testing-your-theme/with-vite-or-webpack-in-dev-mode.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
