Ctrl K
ComunidadGuías…

nextcloud-app/vite.config.js

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { fileURLToPath } from 'url'
import pkg from './package.json' with { type: 'json' }

const __dirname = path.dirname(fileURLToPath(import.meta.url))

export default defineConfig({
	plugins: [vue()],
	define: {
		appName: JSON.stringify(pkg.name),
		appVersion: JSON.stringify(pkg.version),
	},
	// `base: ''` makes Vite's preload helper resolve dynamic chunks and their
	// CSS deps via `import.meta.url` instead of the document root, so the bundle
	// works regardless of where NC mounts the app (e.g. /custom_apps/aiquila/js/).
	base: '',
	build: {
		outDir: 'js/dist',
		emptyOutDir: true,
		// Vite auto-injects CSS only for dynamically imported chunks; entry
		// stylesheets have to be linked by the host page. The manifest is how
		// lib/Template/ViteAssets.php finds them. Written to js/dist/manifest.json
		// rather than Vite's default js/dist/.vite/ so packaging cannot drop it
		// as a dotfile.
		manifest: 'manifest.json',
		// `vendor-nextcloud-vue` alone is ~800 KB and is the floor we can't shrink
		// without dropping @nextcloud/vue; raise the warning so other regressions
		// stay visible.
		chunkSizeWarningLimit: 1000,
		rollupOptions: {
			input: {
				'aiquila-main': path.resolve(__dirname, 'src/main.js'),
				'aiquila-dashboard': path.resolve(__dirname, 'src/dashboard.js'),
				'aiquila-admin': path.resolve(__dirname, 'src/admin.js'),
				'aiquila-personal': path.resolve(__dirname, 'src/personal.js'),
			},
			output: {
				format: 'es',
				entryFileNames: '[name].js',
				chunkFileNames: '[name]-[hash].js',
				manualChunks(id) {
					if (!id.includes('node_modules')) return
					if (id.includes('@nextcloud/vue')) return 'vendor-nextcloud-vue'
					if (id.includes('vue-material-design-icons') || id.includes('@mdi/')) {
						return 'vendor-icons'
					}
					// highlight.js is left out on purpose: src/utils/markdown.js
					// imports its core and each grammar dynamically, and pinning
					// it here would merge them back into one eagerly loaded chunk.
					if (id.includes('/marked/')) return 'vendor-markdown'
				},
			},
		},
	},
	resolve: {
		alias: {
			'@': path.resolve(__dirname, 'src'),
		},
	},
})