SensioLabs Minify Bundle composer require sensiolabs/minify-bundle Minify integration SensioLabs Minify Bundle integrates Minify into Symfony Asset Mapper. Asset Minifier ✅ Minify CSS and JS files, remove whitespace, comments, and more.. 🌍 Reduces the size of your assets by up to 70% (see metrics below). 🚀 Improves the loading time of your website, and the user experience. Asset Mapper 🎯 Automatically minify…
Depending on your deployment process, you might want to enable the
bundle only in the desired environment(s).
Usage
If you use AssetMapper, run the following command to minify all the assets:
php bin/console asset-map:compile
This command is usually run when serving assets in production and the
SensioLabs Minify Bundle will hook into it to minify all assets while copying them.
Command Line
You can also minify assets manually with the command line. First, make sure that
the binary file used to minify assets is properly installed in your computer:
php bin/console minify:install
Then, run the following command to minify assets:
# this outputs the result in the console
php bin/console minify:asset css/main.css
# this will write the output into the 'main.min.css' file
# (the given output file is created / overwritten if needed)
php bin/console minify:asset css/main.css css/main.min.css
Configuration
AssetMapper
# config/packages/sensiolabs_minify.yaml
sensiolabs_minify:
asset_mapper:
# you can minify only CSS files, only JS files or both
types:
css: true # (default: true)
js: true # (default: true)
# a list of assets to exclude from minification (default: [])
# the values of the list can be any shell wildcard patterns
ignore_paths:
- 'admin/*'
- '*.min.js'
# whether to exclude the assets stored in vendor/ from minification;
# these assets are usually pre-minified, so it's common to exclude them
ignore_vendor: true # (default: true)
Minify Binary
Local binary
The minification is performed by a binary file that can be installed on your
computer/server or downloaded automatically by the bundle. This is the default
configuration used by the bundle:
# config/packages/sensiolabs_minify.yaml
sensiolabs_minify:
# ...
minify:
# this disables the usage of local binaries
local_binary: false
# if TRUE, the bundle will download the binary from GitHub
download_binary: '%kernel.debug%'
# the local path where the downloaded binary is stored
download_directory: '%kernel.project_dir%/var/minify'
# the Minify version to download (default: null for latest)
version: null
You can customize this configuration to use a local binary:
# config/packages/sensiolabs_minify.yaml
sensiolabs_minify:
# ...
minify:
# set it to 'auto' to let the bundle try to find the location of the binary
local_binary: 'auto'
# you can also define the path to the binary explicitly, but this won't work
# if you run the application in multiple servers with different binary locations
local_binary: "/usr/local/bin/minify"
评论