import { loadEnv } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import path from 'path';
// import viteCompression from 'vite-plugin-compression';
import uniReadPagesV3Plugin from './common/router/utils/uni-read-pages-v3';
import mpliveMainfestPlugin from './common/libs/mplive-manifest-plugin';


// https://vitejs.dev/config/
export default (command, mode) => {
	const env = loadEnv(mode, __dirname, 'SOUND_CHAIN_');
	return {
		envPrefix: "SOUND_CHAIN_",
		plugins: [
			uni(),
			// viteCompression({
			// 	verbose: false
			// }),
			uniReadPagesV3Plugin({
				pagesJsonDir: path.resolve(__dirname, './pages.json'),
				includes: ['path', 'aliasPath', 'name', 'meta'],
			}),
			mpliveMainfestPlugin(env.SOUND_CHAIN_MPLIVE_ON)
		],
		server: {
			host: true,
			// open: true,
			port: env.SOUND_CHAIN_DEV_PORT,
			proxy: {
				"/api": {
					target: 'http://192.168.1.251:18993',
					changeOrigin: true,
					rewrite: (path) => path.replace(/^\/api/, ''),
				},
			},
			hmr: {
				overlay: true,
			}
		},
	};
};
