import { fileURLToPath, URL } from 'node:url' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' // https://vite.dev/config/ export default defineConfig({ plugins: [ vue(), { name: 'inject-css-filename', enforce: 'post', generateBundle(_options, bundle) { // Find the CSS file in the bundle const cssFile = Object.keys(bundle).find(name => name.endsWith('.css')) if (!cssFile) { console.warn('No CSS file found in bundle') return } // Find and update all JS chunks // Prefix with static/ to match nginx location pattern: /modules/{handle}/static/{file} for (const fileName of Object.keys(bundle)) { const chunk = bundle[fileName] if (chunk.type === 'chunk' && chunk.code.includes('__CSS_FILENAME_PLACEHOLDER__')) { chunk.code = chunk.code.replace( /__CSS_FILENAME_PLACEHOLDER__/g, `static/${cssFile}` ) console.log(`Injected CSS filename "static/${cssFile}" into ${fileName}`) } } } } ], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), '@KTXC': fileURLToPath(new URL('../../core/src', import.meta.url)), '@FileManager': fileURLToPath(new URL('../file_manager/src', import.meta.url)), }, }, build: { outDir: 'static', emptyOutDir: true, sourcemap: false, lib: { entry: fileURLToPath(new URL('./src/main.ts', import.meta.url)), name: 'Files', formats: ['es'], fileName: () => 'module.mjs', }, rollupOptions: { external: [ 'vue', 'vue-router', 'pinia', ], output: { // Use content hash for CSS files assetFileNames: (assetInfo) => { if (assetInfo.name?.endsWith('.css')) { return 'files-[hash].css' } return '[name]-[hash][extname]' } } }, }, })