From 8c238a7326f4759d735f1532b25566d92793f8fa Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Fri, 5 Apr 2024 09:50:23 +0200 Subject: [PATCH] Mention that libraries are not minified by default --- src/features/production.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/features/production.md b/src/features/production.md index ce9683f63..7d099cb32 100644 --- a/src/features/production.md +++ b/src/features/production.md @@ -21,10 +21,30 @@ Parcel includes many optimizations designed to reduce bundle sizes, including au Parcel includes minifiers for JavaScript, CSS, HTML, and SVG out of the box. Minification reduces the file size of your output bundles by removing whitespace, renaming variables to shorter names, and many other optimizations. -By default, minification is enabled when using the `parcel build` command. You can use the `--no-optimize` CLI flag to disable minification and other optimizations if needed. +By default, minification is enabled when using the `parcel build` command (except when [building libraries](/getting-started/library/)). You can use the `--no-optimize` CLI flag to disable minification and other optimizations if needed. Parcel uses [SWC](https://swc.rs) to minify JavaScript, [lightningcss](https://lightningcss.dev) for CSS, [htmlnano](https://github.com/posthtml/htmlnano) for HTML, and [svgo](https://github.com/svg/svgo) for SVG. If needed, you can configure these tools using a `.terserrc`, `.htmlnanorc`, or `svgo.config.json` config file. See the docs for [JavaScript](/languages/javascript/), [CSS](/languages/css/), [HTML](/languages/html), and [SVG](/languages/svg/) for more details. +To minify library builds, override the `optimize` target option: + +{% sample %} +{% samplefile "package.json" %} + +```json +{ + "targets": { + "main": { + "optimize": true + } + } +} +``` + +{% endsamplefile %} +{% endsample %} + + + ### Tree shaking In production builds, Parcel statically analyzes the imports and exports of each module, and removes everything that isn't used. This is called "tree shaking" or "dead code elimination". Tree shaking is supported for both static and dynamic `import()`, CommonJS and ES modules, and even across languages with CSS modules.