Loheide-eu-mitarbeiterplatt.../sdk/vite.js
Friederich Loheide f3eebbef0f
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m31s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m44s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m18s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m35s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m38s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m28s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 45s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m13s
Kopfzeilen-Symbole für Plugins (0.39.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 16:13:33 +00:00

88 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 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,header}/
* 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', 'header'];
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/<pages|widgets|blocks|profile|profile-panels|editorial|header>/.');
}
return {
plugins: [vue(), tailwindcss(), manifest(Object.keys(input))],
// Plugins laufen unter /plugin-assets/<slug>/<version>/ – 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) });
},
};
}