import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import AutoIpmort from 'unplugin-auto-import/vite'
import { UnifiedViteWeappTailwindcssPlugin as uvwt } from "weapp-tailwindcss/vite";

const path = require("path");
const isH5 = process.env.UNI_PLATFORM === "h5";
const isApp = process.env.UNI_PLATFORM === "app";
const WeappTailwindcssDisabled = isH5 || isApp;
const resolve = (p) => {
	return path.resolve(__dirname, p);
};

export default defineConfig({
	ignoreDevUnusedFiles: false,
	ignoreUploadUnusedFiles: false,
	plugins: [
		uni(),
		AutoIpmort({
			imports: ['vue', 'pinia', 'uni-app']
		}),
		uvwt({
			rem2rpx: true,
			disabled: WeappTailwindcssDisabled,
			tailwindcssBasedir: __dirname
		})
	],
	css: {
		postcss: {
			plugins: [
				require("tailwindcss")({
					config: resolve("./tailwind.config.js")
				}),
				require("autoprefixer")
			],
		},
	},
	build: {
		minify: 'terser',
		terserOptions: {
			compress: {
				drop_console: false,
			},
		},
	},
	optimizeDeps: {
		exclude: ['vue-qrcode-reader']
	}
})
