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.