How to clear() when vite build
1. Remove console in vue-cli and downloadbabel-plugin-transform-remove-console
Plugin, configuration file
2. Vite build clear(): In the vscode project, find the file:
Configure the following configuration, mainly the build block configuration
import { defineConfig,loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' export default defineConfig({ plugins: [vue()], build:{ minify: 'terser', terserOptions: { compress: { //Remove() in production environment drop_console: true, drop_debugger: true, }, }, }, })
Causes memory leaks. Automatic removal method when packaging
webpack via tool: terser
You need to install it before use
const { defineConfig } = require('@vue/cli-servise'); = defineConfig({ transpileDependencies:true, terser:{ terserOptions:{ compress:{ drop_console:true, drop_debugger:true, }, }, }, });
Then it will be automatically removed by packaging directly without affecting the development environment
If it's vue3+vite
import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; export default defineConfig({ plugins:[vue()], build:{ minify:'terser', terserOptions:{ compress:{ drop_console:true, drop_debugger:true, }, }, }, });
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.