reactjsviteminifybundling-and-minificationpreact

How to remove @license comments from source during npm build (will add manually)?


I am developing a Vite-React webapp to be used by me only, and heres my simple build command in package.json: "build": "vite build --emptyOutDir --base=./".

It uses the Google Firebase libraries that contains several submodules wherein each has the exact same @license comment leading to 48 times the same repeated text contributing to 80% of my build since everything else I have gzipped anyway. Now I have no issue with manually, thankfully, and carefully adding all unique licenses wherever appropriate, but at first I wish to remove licenses during the build.

I realize the "@license" is probably the marker the minifier looks for, and I searched around but could not find a way to turn it off. Please advise. And Thanks!


Solution

  • The default minifier now is esbuild (https://vitejs.dev/config/build-options.html#build-minify).

    Here is the new config that works:

    export default defineConfig({
      // ...
      build: {
        // ...
      },
      esbuild: { legalComments: 'none' },
    })
    
    

    https://esbuild.github.io/api/#legal-comments