Skip to content

Commit 0806b4c

Browse files
authored
fix(keycloak-theme): force build to resolve React from package path (#2353)
Signed-off-by: Petr Kadlec <petr@puradesign.cz>
1 parent 0d01fe2 commit 0806b4c

1 file changed

Lines changed: 28 additions & 24 deletions

File tree

apps/keycloak-theme/vite.config.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,66 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import react from "@vitejs/plugin-react";
7-
import { keycloakify } from "keycloakify/vite-plugin";
8-
import path from "path";
9-
import { defineConfig } from "vite";
10-
import { viteStaticCopy } from "vite-plugin-static-copy";
11-
import svgr from "vite-plugin-svgr";
6+
import react from '@vitejs/plugin-react';
7+
import { keycloakify } from 'keycloakify/vite-plugin';
8+
import { createRequire } from 'module';
9+
import path from 'path';
10+
import { defineConfig } from 'vite';
11+
import { viteStaticCopy } from 'vite-plugin-static-copy';
12+
import svgr from 'vite-plugin-svgr';
1213

13-
const THEME_NAME_AGENTSTACK = "agentstack";
14-
const THEME_NAME_AGENTSTACK_SSO = "agentstack-sso";
14+
const THEME_NAME_AGENTSTACK = 'agentstack';
15+
const THEME_NAME_AGENTSTACK_SSO = 'agentstack-sso';
16+
const require = createRequire(import.meta.url);
17+
18+
const resolvePackageDir = (packageName: string) => path.dirname(require.resolve(`${packageName}/package.json`));
1519

1620
export default defineConfig({
1721
define: {
18-
"import.meta.env.VITE_APP_NAME": JSON.stringify(
19-
process.env.APP_NAME || "Agent Stack",
20-
),
22+
'import.meta.env.VITE_APP_NAME': JSON.stringify(process.env.APP_NAME || 'Agent Stack'),
2123
},
2224
plugins: [
2325
react(),
2426
svgr(),
2527
viteStaticCopy({
2628
targets: [
2729
{
28-
src: path.join(
29-
__dirname,
30-
"node_modules/@ibm/plex/IBM-Plex-Sans/fonts/split/woff2/*.woff2",
31-
),
32-
dest: "assets/~@ibm/plex/IBM-Plex-Sans/fonts/split/woff2",
30+
src: path.join(__dirname, 'node_modules/@ibm/plex/IBM-Plex-Sans/fonts/split/woff2/*.woff2'),
31+
dest: 'assets/~@ibm/plex/IBM-Plex-Sans/fonts/split/woff2',
3332
},
3433
],
3534
}),
3635
keycloakify({
37-
accountThemeImplementation: "none",
36+
accountThemeImplementation: 'none',
3837
themeName: [THEME_NAME_AGENTSTACK, THEME_NAME_AGENTSTACK_SSO],
3938
}),
4039
],
4140
css: {
4241
modules: {
43-
generateScopedName: "[name]__[local]__[hash:base64:5]",
42+
generateScopedName: '[name]__[local]__[hash:base64:5]',
4443
},
4544
preprocessorOptions: {
4645
scss: {
47-
api: "modern",
46+
api: 'modern',
4847
quietDeps: true,
4948
additionalData: `@use 'styles/common' as *; @use 'sass:math';`,
5049
includePaths: [
51-
path.join(__dirname, "node_modules"),
52-
path.join(__dirname, "src"),
53-
path.join(__dirname, "../agentstack-ui/src"),
50+
path.join(__dirname, 'node_modules'),
51+
path.join(__dirname, 'src'),
52+
path.join(__dirname, '../agentstack-ui/src'),
5453
],
55-
loadPaths: [path.join(__dirname, "../agentstack-ui/src")],
54+
loadPaths: [path.join(__dirname, '../agentstack-ui/src')],
5655
},
5756
},
5857
},
5958
resolve: {
59+
dedupe: ['react', 'react-dom'],
6060
alias: {
61-
styles: path.resolve(__dirname, "../agentstack-ui/src/styles"),
61+
react: resolvePackageDir('react'),
62+
'react/jsx-runtime': require.resolve('react/jsx-runtime'),
63+
'react/jsx-dev-runtime': require.resolve('react/jsx-dev-runtime'),
64+
'react-dom': resolvePackageDir('react-dom'),
65+
styles: path.resolve(__dirname, '../agentstack-ui/src/styles'),
6266
},
6367
},
6468
});

0 commit comments

Comments
 (0)