import svelte from '@sveltejs/vite-plugin-svelte';
import { minify } from 'html-minifier';
import { defineConfig } from 'vite';
//
const indexReplace = () => {
	return {
		name: 'html-transform',
		transformIndexHtml(html) {
			return minify(html, {
				collapseWhitespace: true
			});
		}
	};
};

export default defineConfig(({ command, mode }) => {
	const isProduction = mode === 'production';
	return {
		// base: './',
		build: {
			polyfillDynamicImport: false,
			cssCodeSplit: false,
			minify: isProduction,
			target: ["es2020", "esnext", "edge88", "chrome87", "safari14"]
		},
		plugins: [
			svelte({
				//@ts-ignore
				hot: !isProduction,
				emitCss: true,
				extensions: ['.md', '.svx', '.svelte'],
				preprocess: [
					//
				]
			}),
			indexReplace()
		]
	};
});
