Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract license info outside of the JavaScript bundle #17892

Open
4 tasks done
nojaf opened this issue Aug 16, 2024 · 4 comments · May be fixed by #18104
Open
4 tasks done

Extract license info outside of the JavaScript bundle #17892

nojaf opened this issue Aug 16, 2024 · 4 comments · May be fixed by #18104
Labels
enhancement New feature or request p3-significant High priority enhancement (priority)

Comments

@nojaf
Copy link

nojaf commented Aug 16, 2024

Description

This is something between a bug and a feature I guess, but I notice that my JS bundle contains a lot of similar license code comments.

Sample: https://stackblitz.com/edit/vitejs-vite-k6vbhh?file=dist%2Fassets%2Findex-trimmed.js

After removing these with uglify-js I see about 20% file size decrease.

npx uglify-js ./dist/assets/index-DQVm2kVJ.js --output ./dist/assets/index-trimmed.js
-rw-rw-r--  1  staff  staff  475905  Aug  16  14:27  index-DQVm2kvJ.js    
-rw-rw-r--  1  staff  staff  371060  Aug  16  14:32  index-trimmed.js    

While these licenses are important, my average website visitor won't really bat an eye about this.

Suggested solution

I'm wondering if Vite could extract all the comments and place them into a license.txt file and link that in my bundled.js instead.

Alternative

I guess I can do post processing myself to deal with this.

Additional context

The firebase package does seem to bring a lot of very similar Google licenses. So you only have this problem based on what packages you use.

Validations

Copy link

stackblitz bot commented Aug 16, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Aug 17, 2024

I think esbuild is preserving @license comment by default https://esbuild.github.io/api/#legal-comments
You can use esbuild.legalComments: "none" to strip all comments:

import { defineConfig } from 'vite';

export default defineConfig({
  esbuild: {
    legalComments: 'none',
  },
});

Probably what you want is esbuild.legalComments: "linked", but unfortunately this is not supported for Vite build since Vite uses esbuild to trasnform individual files chunks.

Not sure but maybe you can try other plugins to get back the licenses separately not from the code comment? something like https://github.com/mjeanroy/rollup-plugin-license

@Ada541
Copy link

Ada541 commented Aug 23, 2024

okay

@bluwy
Copy link
Member

bluwy commented Sep 1, 2024

I'm personally inclined to mark this as an enhancement since it would be a nice default for Vite to auto manage and emit licenses when building apps.

@sapphi-red sapphi-red added enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) p3-significant High priority enhancement (priority) and removed enhancement: pending triage p2-nice-to-have Not breaking anything but nice to have (priority) labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p3-significant High priority enhancement (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants