????????在生產環境上,務必要將日志清除干凈,其因有二,在webgis系統中,有很多幾何數據,體積大、數量多,很容易引起系統卡頓;清除log后,系統看著舒服,協同開發有很多無聊的日志,打出來沒必要。
? ? ? ? vite中已經內置移除console的設置,只需簡單配置即可生效。在配合文件根目錄下開啟build的配置。
build: {minify: 'terser',terserOptions: {compress: {//生產環境時移除console、debuggerdrop_console: true,drop_debugger: true,},},},
? ? ? ? 全局位置如下:
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import eslintPlugin from 'vite-plugin-eslint';
import { VantResolve, createStyleImportPlugin } from 'vite-plugin-style-import';
import path from 'path';
import { svgBuilder } from './scripts/svg-builder';
import { viteVConsole } from 'vite-plugin-vconsole';
import vueJsx from '@vitejs/plugin-vue-jsx';
import compression from 'vite-plugin-compression';function resolve(dir: string) {return path.join(__dirname, dir);
}// https://vitejs.dev/config/
export default defineConfig({base: './',server: {proxy: {'/dgp-oms-server-web': 'http://192.168.1.196:8650'}},plugins: [vue(),vueJsx(),eslintPlugin({fix: true}),createStyleImportPlugin({libs: [{libraryName: 'vant',esModule: true,resolveStyle: (name) => `../es/${name}/style`}]}),compression(),svgBuilder('./src/svg/') // 導入全部svg,無需再單獨導入// viteVConsole({// entry: path.resolve('src/main.ts'), // entry file// localEnabled: false, // dev environment// enabled: true, // build production// config: {// maxLogNumber: 1000,// theme: 'dark'// }// })],build: {minify: 'terser',terserOptions: {compress: {//生產環境時移除console、debuggerdrop_console: true,drop_debugger: true,},},},resolve: {extensions: ['.ts', '.tsx', '.vue', '.json', '.jsx', '.mjs', '.js'],alias: {'@': resolve('./src')}},css: {modules: {localsConvention: 'camelCase'},preprocessorOptions: {// scss全局預定義變量scss: {additionalData: '@import "@/styles/index.scss";'}}}
});
? ? ? ? 測試結果:
開啟前打包后有日志,開啟后打包上線無日志,主打一個清爽。