import {defineConfig} from 'vite' import vue from '@vitejs/plugin-vue' function helloPlugin() { console.log("hello Plugin") return { name: 'helloPlugin', transform(src, id) { // 只处理 src 目录下的文件,跳过 node_modules if (!id.includes('/src/')) return null // 生产环境:自动移除 console.log if (process.env.NODE_ENV === 'production') { const result = src.replace(/console\.log\([^)]*\);?/g, '') return {code: result, map: null} } return null } } } // https://vite.dev/config/ export default defineConfig({ plugins: [ vue(), helloPlugin() ], clear:true })