Add option to minify `es` format in library mode

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
aleclarsoncommented, 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.

2reactions
johnpangaloscommented, Oct 19, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES Modules / `es` outputs not minified · Issue #6079 · vitejs/vite
When setting up a new Vite project to build a package, all output formats appear to be minified except for the es /...
Read more >
Build Options - Vite
Note the build.minify option does not minify whitespaces when using the 'es' format in lib mode, as it removes pure annotations and breaks...
Read more >
Build A Library With esbuild - Medium
The esm format stands for "ECMAScript module". It assumes the environment supports import and export syntax (documentation). To bundle such a ...
Read more >
API - ESBuild
The build API can take the following options: Simple options: Alias; Bundle; Define; Entry points; External; Format; Inject; Loader; Minify; Outdir; Outfile ...
Read more >
How to build minified and uncompressed bundle with webpack?
As the manual explains, the plugin can be replaced with minimize option. Custom configuration can be provided to the plugin by specifying UglifyJsPlugin ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found