import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import tryFiles from "./src/lib/try_files.js"

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
	return {
		plugins: [
			tryFiles,
			vue(),
		],
		resolve: {
			alias: {
				'@': fileURLToPath(new URL('./src', import.meta.url))
			}
		},
		server: {
			host: '0.0.0.0',
			port: 5174
		},
		root: 'src',
		publicDir: '@/public',
		build: {
			rollupOptions: {
				input: [
					'@/views/index/index.html',
					'@/views/account/reset.html',
					'@/views/email/verify.html',
					'@/views/login/index.html',
					'@/views/login/ticket.html',
					'@/views/login/otp.html',
					'@/views/register/index.html',
					'@/views/layout.html',

					/** portal **/
					'@/views/portal/index.html',
					'@/views/portal/post.html',
					'@/views/portal/products/index.html',
					'@/views/portal/products/cdn/index.html',
				],
				output: {
					assetFileNames: 'views/assets/app-[hash].[ext]',
					entryFileNames: 'views/assets/app-[hash].js',
					chunkFileNames: 'views/assets/app-[hash].js',
					dir: 'dist'
				}
			},
			chunkSizeWarningLimit: 2048
		}
	}
})
