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

Add option to minify es format in library mode #5167

Closed
4 tasks done
DerYeger opened this issue Oct 1, 2021 · 6 comments · Fixed by #6314
Closed
4 tasks done

Add option to minify es format in library mode #5167

DerYeger opened this issue Oct 1, 2021 · 6 comments · Fixed by #6314

Comments

@DerYeger
Copy link

DerYeger commented Oct 1, 2021

Clear and concise description of the problem

In Vite v2.6.0, the es format is no longer minified in library mode.
I understand that this is necessary for proper tree-shaking.
However, libraries that cannot benefit from tree-shaking (e.g. a single exported Vue component) are still limited to un-minified files.

Suggested solution

Add an explicit option to minify es format in library mode.

Alternative

No response

Additional context

No response

Validations

@DerYeger DerYeger changed the title Add option to minify `es format in library mode Add option to minify es format in library mode Oct 1, 2021
@Niputi
Copy link
Contributor

Niputi commented Oct 1, 2021

ref 06d86e4

according to change its currently not possible to enable minify for es output which make sense as people potentially could enable something breaking tree shaking

@DerYeger
Copy link
Author

DerYeger commented Oct 1, 2021

ref 06d86e4

according to change its currently not possible to enable minify for es output which make sense as people potentially could enable something breaking tree shaking

Yes, this recent change prevents es output from being minimized and I understand why it was implemented.
However, I strongly believe that adding another tool for the minification of libraries with a single export should not be necessary, since the functionality is already there.
Adding a new configuration option would fix this issue.

@bluepower
Copy link
Contributor

Agree. For example: the es output of petite-vue's lib mode, the size is too much bigger than before.

vite v2.6.2 building for production...
dist/petite-vue.es.js 43.14 KiB

vite v2.5.10 building for production...
dist/petite-vue.es.js 16.42 KiB

@aleclarson
Copy link
Member

aleclarson commented Oct 7, 2021

You can use a CDN like jsDelivr, which allows auto-minification by adding .min before the file extension.

That said, CDNs are an anti-pattern these days, due to HTTP cache partitioning. You end up downloading more data than if you bundled, because less byte compression can be done.

Additionally, minifying your library is hostile to NPM users, since it can make debugging more difficult, and it prohibits the use of tools like patch-package.

@gwsbhqt
Copy link

gwsbhqt commented Oct 8, 2021

I suggest adding options to allow minimization when using esbuild to package, sometimes not just build libraries into npm, and sometimes debugging information is not needed.

@johnpangalos
Copy link

I think there are legitimate uses for cdn libraries, like if you want to create a package that is to be used outside of a node framework. Sure the caching might not work between websites but that's not the main feature of a CDN based javascript library, the main feature is that it is accessible via the web.

What is the use case for library mode? Because this combined with not being able to inject css styles makes me think that there is a very specific use case in mode. If it's specifically creating pure javascript modules for npm and usage in the node ecosystem that's perfectly acceptable and maybe the answer is that it's specified in the vite documentation and people who need further functionality either create something else rollup or webpack based.

Or maybe even library mode should be it's own vite like offshoot package that supports a breadth of use cases. Tsdx exists but it hasn't been updated in a year.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants