uikit/vite.config.js
2026-07-09 12:22:34 +03:30

110 lines
2.2 KiB
JavaScript

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
const externalPackages = [
"react",
"react-dom",
"react/jsx-runtime",
"@chakra-ui/react",
"@emotion/react",
"@emotion/styled",
"framer-motion",
"keycloak-js",
"axios",
"@tanstack/react-query",
"@tanstack/react-table",
"react-icons",
"react-hook-form",
"react-select",
"chakra-react-select",
];
export default defineConfig(({ mode }) => {
if (mode === "remote") {
return {
plugins: [react()],
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
},
build: {
outDir: "dist",
emptyOutDir: false,
target: "es2020",
lib: {
entry: path.resolve(process.cwd(), "src/remote/ui/GBadge.remote.jsx"),
formats: ["es"],
},
rollupOptions: {
output: {
entryFileNames: "remote/GBadge.js",
inlineDynamicImports: true,
},
},
},
};
}
return {
plugins: [react()],
build: {
lib: {
entry: {
index: path.resolve(process.cwd(), "src/index.js"),
utils: path.resolve(process.cwd(), "src/utils/index.js"),
pagination: path.resolve(process.cwd(), "src/pagination/index.js"),
layout: path.resolve(process.cwd(), "src/layout/index.js"),
core: path.resolve(process.cwd(), "src/core/index.js"),
table: path.resolve(process.cwd(), "src/table/index.js"),
form: path.resolve(process.cwd(), "src/form/index.js"),
icons: path.resolve(process.cwd(), "src/icons/index.js"),
"remote-ui": path.resolve(process.cwd(), "src/remote/ui/index.jsx"),
},
formats: ["es"],
},
rollupOptions: {
external: (id) => {
return (
externalPackages.includes(id) ||
id.startsWith("react-icons/") ||
id.startsWith("@emotion/") ||
id.startsWith("react-select/")
);
},
output: {
entryFileNames: "[name].js",
chunkFileNames: "chunks/[name]-[hash].js",
assetFileNames: "assets/[name]-[hash][extname]",
},
},
},
};
});