To remove console from vue-CLI, you need to download babel-plugin-transform-remove-console, but it is already built-in in Vite, so you just need to configure it. However, this configuration is global, that is, the development and production environments are unified, and the development and production environments need to be differentiated.

//vite.config.js

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

var terserOptions = {}
if ((process.env.NODE_ENV = 'production')) {
    terserOptions = {
        compress: {
            drop_console: true.drop_debugger: true,}}}export default defineConfig({
    plugins: [vue()],
    build: {
        terserOptions,
    },
})
Copy the code