Remove console statements from other developers and keep only your own!



This content originally appeared on DEV Community and was authored by ctjj

As developers, I believe everyone must have encountered a lot of logs in the console, which greatly reduces our development efficiency

Now, I recommend a self-developed Vite plugin that can remove logs not belonging to the user during packaging based on the git author information

rollup-plugin-remove-others-console:Remove console statements from other developers and keep only your own, making your development more refreshing!

Welcome star and follow me!

install

npm i rollup-plugin-remove-others-console -D

use

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import removeOthersConsole from "rollup-plugin-remove-others-console";

export default defineConfig({
  plugins: [
    removeOthersConsole(),
    // . .. others
  ],
});

warn

1. Not recommended for use in production environments

If packaging only leaves the packager’s console.log statement, it may affect other developers’ debugging, although this is a bad habit!

You can use the official Vite method to drop all console statements based on the following example.

//vite.config.js
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
  plugins: [vue()],
  build: {
    minify: "terser",
    terserOptions: {
      compress: {
        //Remove console in production environment
        drop_console: true,
        drop_debugger: true,
      },
    },
  },
});

2. Please ensure that the files being processed are the most original ones

Due to the strict dependence of the plugin on line interpretation of Git authors, it is necessary to ensure that the plugin is executed before any plugins that may modify the source file.


This content originally appeared on DEV Community and was authored by ctjj