Files
server/vite.config.ts
Sebastian Krupinski bb05f3d20f
All checks were successful
JS Unit Tests / test (pull_request) Successful in 16s
Build Test / build (pull_request) Successful in 20s
PHP Unit Tests / test (pull_request) Successful in 54s
refactor: module federation
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-02-22 12:35:56 -05:00

110 lines
3.3 KiB
TypeScript

import { defineConfig, type PluginOption } from 'vite';
import vue from '@vitejs/plugin-vue';
import vuetify from 'vite-plugin-vuetify';
import path from 'path';
import { fileURLToPath } from 'url';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import { generateVendorShims } from './scripts/generate-vendor-shims';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const runVendorShimGenerator = async (outputDir: string) => {
await generateVendorShims({ outputDir, silent: true });
};
const generateVendorShimsPlugin = (): PluginOption => {
let outDir = 'dist';
let rootDir = process.cwd();
return {
name: 'generate-vendor-shims',
apply: 'build',
configResolved(config) {
outDir = config.build.outDir;
rootDir = config.root;
},
async closeBundle() {
try {
const resolvedOutDir = path.isAbsolute(outDir) ? outDir : path.resolve(rootDir, outDir);
const vendorDestination = path.resolve(resolvedOutDir, 'vendor');
await runVendorShimGenerator(vendorDestination);
} catch (error) {
console.warn('[generate-vendor-shims] Failed to update vendor shims', error);
}
},
};
};
// https://vite.dev/config/
export default defineConfig(({ mode }) => ({
root: path.resolve(__dirname, 'core/src'),
plugins: [
vue(),
vuetify(),
generateVendorShimsPlugin(),
viteStaticCopy({
targets: [
{
src: path.resolve(__dirname, 'core/lib/index.php'),
dest: path.resolve(__dirname, 'public'),
},
],
}),
],
resolve: {
alias: {
'@KTXC': path.resolve(__dirname, 'core/src'),
},
},
server: {
fs: {
allow: ['..'], // Allow serving files from one level up to find the project root
},
host: true,
},
build: {
outDir: path.resolve(__dirname, 'public'),
emptyOutDir: true,
minify: mode === 'production',
sourcemap: true,
rollupOptions: {
input: {
public: path.resolve(__dirname, 'core/src/public.html'),
private: path.resolve(__dirname, 'core/src/private.html'),
'ktxc': path.resolve(__dirname, 'core/src/shared/index.ts'),
},
preserveEntrySignatures: 'exports-only',
output: {
// Preserve export names for ktxc (used via import map by modules)
minifyInternalExports: false,
entryFileNames: (chunkInfo) => {
// Keep ktxc without hash for stable import map references
if (chunkInfo.name === 'ktxc') {
return `js/ktxc.mjs`;
}
return `js/[name]-[hash].js`;
},
chunkFileNames: (chunkInfo) => {
return `js/[name]-[hash].js`;
},
assetFileNames: (assetInfo) => {
if (assetInfo.name) {
const extType = assetInfo.name.split('.').pop();
if (extType && /png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
return `images/[name]-[hash][extname]`;
}
if (extType && /woff|woff2|eot|ttf|otf/i.test(extType)) {
return `fonts/[name]-[hash][extname]`;
}
if (extType === 'css') {
return `css/[name]-[hash][extname]`;
}
}
return `[name]-[hash][extname]`;
},
},
},
},
}));