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 = 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, }, }, }, });