Files
laravel-manager/ui/vite.config.ts
T
Matthijs Iriks 3345797141
PR CI / ledger (pull_request) Successful in 4s
PR CI / flow (pull_request) Successful in 4s
PR CI / ui (pull_request) Successful in 16s
PR CI / test (lowest) (pull_request) Successful in 44s
PR CI / test (stable) (pull_request) Successful in 49s
PR CI / security (pull_request) Successful in 50s
PR CI / pr-ci (pull_request) Successful in 2s
PR CI / release-automerge (pull_request) Successful in 4s
Add resources defined in config and a bundle of the site's own screens
2026-12-04 05:26:37 +01:00

40 lines
1.7 KiB
TypeScript

import tailwindcss from '@tailwindcss/vite';
import vue from '@vitejs/plugin-vue';
import { defineConfig, type Plugin } from 'vite';
// One script and one stylesheet with fixed names: the package serves them itself (resources/dist), so a site needs
// no Node. `npm run build` here, and commit the result.
// A site's own bundle imports `vue` like any component library would. `vue.js` makes that the Vue of the screens (an import map
// in the shell points `vue` at it), by re-exporting what the screens put on `window.IriksManager.Vue`.
function vueForExtensions(): Plugin {
return {
name: 'manager-vue-for-extensions',
async generateBundle() {
const loaded: Record<string, unknown> = await import('vue');
const names = [...new Set([...Object.keys(loaded), ...Object.keys((loaded.default as object) ?? {})])].filter((name) => /^[A-Za-z_$][\w$]*$/.test(name) && name !== 'default');
const source = `const Vue = window.IriksManager.Vue;\n${names.map((name) => `export const ${name} = Vue.${name};`).join('\n')}\nexport default Vue;\n`;
this.emitFile({ type: 'asset', fileName: 'vue.js', source });
},
};
}
export default defineConfig({
plugins: [vue(), tailwindcss(), vueForExtensions()],
build: {
outDir: '../resources/dist',
emptyOutDir: true,
cssCodeSplit: false,
sourcemap: false,
rollupOptions: {
input: 'src/main.ts',
output: {
entryFileNames: 'manager.js',
chunkFileNames: 'manager-[name].js',
assetFileNames: 'manager[extname]',
inlineDynamicImports: true,
},
},
},
});