/** * Vite-Voreinstellung für Inhaus-Plugins (Plugin-SDK). * * // vite.config.js im Plugin * import { defineConfig } from 'vite'; * import { inhausPlugin } from './inhaus-sdk/vite.js'; * export default defineConfig(inhausPlugin()); * * Baut jede Vue-Datei unter resources/js/{pages,widgets,blocks,profile,profile-panels,editorial}/ * als eigenes ES-Modul nach dist/ und schreibt dist/inhaus.json. Vue, Inertia und @inhaus/ui * bleiben extern – das Portal stellt sie per Import Map bereit. */ import { existsSync, globSync } from 'node:fs'; import { resolve } from 'node:path'; import vue from '@vitejs/plugin-vue'; import tailwindcss from '@tailwindcss/vite'; export const KINDS = ['pages', 'widgets', 'blocks', 'profile', 'profile-panels', 'editorial']; export const EXTERNAL = ['vue', '@inertiajs/vue3', '@inhaus/ui']; export function inhausPlugin({ root = process.cwd() } = {}) { const input = {}; for (const kind of KINDS) { for (const file of globSync(`resources/js/${kind}/**/*.vue`, { cwd: root })) { const name = file.replace(`resources/js/${kind}/`, '').replace(/\.vue$/, ''); input[`${kind}/${name}`] = resolve(root, file); } } if (existsSync(resolve(root, 'resources/css/style.css'))) { input.style = resolve(root, 'resources/css/style.css'); } if (Object.keys(input).length === 0) { throw new Error('Keine Oberfläche gefunden: Vue-Dateien gehören nach resources/js//.'); } return { plugins: [vue(), tailwindcss(), manifest(Object.keys(input))], // Plugins laufen unter /plugin-assets/// – Pfade relativ halten base: './', build: { outDir: 'dist', emptyOutDir: true, target: 'es2022', rollupOptions: { input, external: EXTERNAL, preserveEntrySignatures: 'strict', output: { format: 'es', entryFileNames: '[name].js', chunkFileNames: 'chunks/[name]-[hash].js', assetFileNames: 'assets/[name]-[hash][extname]', }, }, }, }; } /** dist/inhaus.json: welche Komponente in welcher Datei steckt, welches CSS dazugehört */ function manifest(entries) { return { name: 'inhaus-manifest', generateBundle(_, bundle) { const components = {}; const css = []; for (const file of Object.values(bundle)) { if (file.type === 'chunk' && file.isEntry && entries.includes(file.name) && file.name !== 'style') { components[file.name] = file.fileName; } if (file.type === 'asset' && file.fileName.endsWith('.css')) { css.push(file.fileName); } } // Leere Hülle des CSS-Einstiegs nicht ausliefern for (const [key, file] of Object.entries(bundle)) { if (file.type === 'chunk' && file.name === 'style') delete bundle[key]; } this.emitFile({ type: 'asset', fileName: 'inhaus.json', source: JSON.stringify({ components, css: [...new Set(css)] }, null, 4) }); }, }; }