Open
Description
Feature Request - Optional Asset Compression
This feature request asks for the implementation of optional asset compression by trunk
.
trunk
would follow a similar pattern to webpack-compression-plugin
by allowing users to configure --build
asset compression for all files generated by trunk
.
NOTE
In relation to #81, I've checked and confirmed that actix-web
and warp
support serving compressed assets.
Example
Cargo.toml
changes
...
[features]
compression = []
gzip-compression = ["compression", "flate2"]
...
[dependencies]
...
flate2 = { version = "1.0.18", default-features = false, features = ["tokio", "zlib"], optional = true }
Configuration in Trunk.toml
...
[[compression]]
# Specifies the compression algorithm.
algorithm = "gzip"
# Options to pass to the compression algorithm. Optional.
# Ex: Passing the `level` option to gzip
options = { level = 6 }
# A RegExp test to pass to include assets that pass the RegExp test. Optional.
test: "/\.(js|css|png|wasm)(\?.*)?$/i"
# Allow for inclusion of certain assets via glob. Optional.
include = []
# Allow for exclusion of certain assets via glob. Optional.
exclude = ["favicon.ico", "*.gz"]
# Size of asset (in bytes) that should be compressed. Less than the threshold will not be compressed. Optional.
threshold = 8192
ratio = 0.8 # Minimum compressed asset size ratio for output. Optional.
Activity