-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
2,409 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/.editorconfig export-ignore | ||
/.git* export-ignore | ||
/.php-cs-fixer.dist.php export-ignore | ||
/doc/ export-ignore | ||
/tests/ export-ignore | ||
/phpunit.dist.xml export-ignore | ||
/phpstan.dist.neon export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
name: "CI" | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
|
||
dep: | ||
name: "Dependencies" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Git: checkout" | ||
uses: actions/checkout@v4 | ||
- name: "PHP: setup 8.3 " | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.3' | ||
coverage: none | ||
tools: composer | ||
- name: "Composer: cache config" | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
- name: "Composer: cache restore" | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
- name: "Composer: validate" | ||
run: composer validate --strict | ||
- name: "Composer: install" | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
- name: "Composer: audit" | ||
run: composer audit | ||
|
||
cs: | ||
name: "Code style" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Git: checkout" | ||
uses: actions/checkout@v4 | ||
- name: "PHP: setup 8.3" | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.3' | ||
coverage: none | ||
tools: php-cs-fixer | ||
- name: "Php-CS-Fixer: version" | ||
run: php-cs-fixer -V | ||
- name: "Php-CS-Fixer: check" | ||
run: php-cs-fixer check --diff | ||
|
||
sa: | ||
name: "Static Analysis" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Git: checkout" | ||
uses: actions/checkout@v4 | ||
- name: "PHP: setup ${{ matrix.php-version }}" | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.3' | ||
coverage: none | ||
tools: phpstan | ||
- name: "Composer: cache config" | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
- name: "Composer: cache restore" | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
- name: "Composer: validate" | ||
run: composer validate --strict | ||
- name: "Composer: install" | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
- name: "PHPStan: version" | ||
run: phpstan --version | ||
- name: "PHPStan: analyse" | ||
run: phpstan analyse src/ | ||
|
||
tests: | ||
name: "Tests (PHP ${{ matrix.php-version }})" | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php-version: | ||
- '8.2' | ||
- '8.3' | ||
fail-fast: false | ||
steps: | ||
- name: "Git: Checkout" | ||
uses: actions/checkout@v4 | ||
- name: "PHP: setup ${{ matrix.php-version }}" | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
coverage: xdebug | ||
ini-values: xdebug.mode=coverage | ||
- name: "PHP: php matcher" | ||
run: | | ||
echo "::add-matcher::${{ runner.tool_cache }}/php.json" | ||
- name: "Composer: cache config" | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
- name: "Composer: cache restore" | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
- name: "Composer: validate" | ||
run: composer validate --strict | ||
- name: "Composer: install" | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
- name: "PHPUnit: version" | ||
run: php vendor/bin/phpunit --version | ||
- name: "PHPUnit: tests" | ||
run: php vendor/bin/phpunit | ||
# - name: "Codecov: upload" | ||
# uses: codecov/[email protected] | ||
# with: | ||
# token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/.phpunit.cache | ||
/.php-cs-fixer.cache | ||
/composer.lock | ||
/phpunit.xml | ||
/tests/Fixtures/var/ | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
$licence = <<<'EOF' | ||
This file is part of the SensioLabs MinifyBundle package. | ||
(c) Simon André - Sensiolabs | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
EOF; | ||
|
||
$finder = (new PhpCsFixer\Finder()) | ||
->in(__DIR__) | ||
->exclude('tests/Fixtures/var') | ||
; | ||
|
||
return (new PhpCsFixer\Config()) | ||
->setRiskyAllowed(true) | ||
->setRules([ | ||
'@PSR12' => true, | ||
'declare_strict_types' => true, | ||
'header_comment' => ['header' => $licence], | ||
]) | ||
->setFinder($finder) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
branches: ["main"] | ||
maintained_branches: ["main"] | ||
doc_dir: "doc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# CHANGELOG | ||
|
||
## 0.9.0 | ||
|
||
- First version of the bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
<picture> | ||
<source media="(prefers-color-scheme: light)" srcset="./minify.svg" /> | ||
<img src="./minify.dark.svg" alt="SensioLabs MinifyBundle for Symfony" width="100%" /> | ||
</picture> | ||
|
||
<div align="center"> | ||
|
||
[![PHP Version](https://img.shields.io/badge/%C2%A0php-%3E%3D%208.3-777BB4.svg?logo=php&logoColor=white)](https://github.com/sensiolabs/minify-bundle/blob/main/composer.json) | ||
[![CI](https://github.com/sensiolabs/minify-bundle/actions/workflows/CI.yaml/badge.svg)](https://github.com/sensiolabs/minify-bundle/actions) | ||
[![Release](https://img.shields.io/github/v/release/sensiolabs/minify-bundle)](https://github.com/sensiolabs/minify-bundle/releases) | ||
[![License](https://img.shields.io/github/license/sensiolabs/minify-bundle?color=82E83F)](https://github.com/sensiolabs/minify-bundle/blob/main/LICENSE) | ||
|
||
</div> | ||
|
||
<h1 align="center">SensioLabs Minify Bundle</h1> | ||
|
||
## Minify integration | ||
|
||
SensioLabs Minify Bundle integrates [Minify](https://github.com/tdewolff/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` assets during the build process. | ||
|
||
📦📦 Compress and store minified assets in the `cache` directory. | ||
|
||
🌿🌿🌿 Download the Minify binary `automatically` from the repository. | ||
|
||
## Minification | ||
|
||
### JavaScript | ||
|
||
| Asset | Before | After | Diff | Compression | Time | | ||
|------------------------|-------:|-------:|-----:|------------------------------------------|------:| | ||
| [Autocomplete.js][1] | 20 kB | 9.2 kB | -54% | ⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 | 8 ms | | ||
| [Bootstrap.js][3] | 145 kB | 62 kB | -57% | ⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 | 10 ms | | ||
| [Video.js][5] | 2.3 MB | 0.7 MB | -71% | ⬜️⬜️⬜️⬜️⬜️⬜️🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 | 42 ms | | ||
| [w3c.org js][7] | 44 kB | 19 kB | -57% | ⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 | 6 ms | | ||
|
||
|
||
### CSS | ||
|
||
| Asset | Before | After | Diff | Compression | Time | | ||
|-----------------------|-------:|-------:|-----:|-------------------------------------------|-----:| | ||
| [Autocomplete.css][2] | 3.1 kB | 2.5 kB | -19% | ⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️🟩🟩🟩🟩🟩 | 2 ms | | ||
| [Bootstrap.css][4] | 281 kB | 232 kB | -18% | ⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️🟩🟩🟩🟩 | 9 ms | | ||
| [Video-js.css][6] | 53 kB | 47 kB | -12% | ⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜⬜️⬜️⬜️⬜️⬜️⬜️⬜️️🟩🟩 | 4 ms | | ||
| [w3c.org css][8] | 111 kB | 70 kB | -37% | ⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️🟩🟩🟩🟩🟩🟩🟩🟩 | 5 ms | | ||
|
||
|
||
## Installation | ||
|
||
Make sure Composer is installed globally, as explained in the | ||
[installation chapter](https://getcomposer.org/doc/00-intro.md) | ||
of the Composer documentation. | ||
|
||
### With Symfony Flex | ||
|
||
Open a command console, enter your project directory and execute: | ||
|
||
```shell | ||
composer require sensiolabs/minify-bundle | ||
``` | ||
|
||
### Without Symfony Flex | ||
|
||
#### Step 1: Download the Bundle | ||
|
||
Open a command console, enter your project directory and execute the | ||
following command to download the latest stable version of this bundle: | ||
|
||
```shell | ||
composer require sensiolabs/minify-bundle | ||
``` | ||
|
||
#### Step 2: Enable the Bundle | ||
|
||
Then, enable the bundle by adding it to the list of registered bundles | ||
in the `config/bundles.php` file of your project: | ||
|
||
```php | ||
// config/bundles.php | ||
|
||
return [ | ||
// ... | ||
Sensiolabs\MinifyBundle\SensiolabsMinifyBundle::class => ['all' => true], | ||
]; | ||
``` | ||
|
||
Depending on your deployment process, you might want to enable the | ||
bundle only in the desired environment(s). | ||
|
||
|
||
## Configuration | ||
|
||
### AssetMapper Settings | ||
|
||
#### Asset types | ||
|
||
```yaml | ||
# config/packages/sensiolabs_minify.yaml | ||
sensiolabs_minify: | ||
asset_mapper: | ||
# Minify CSS and JS files | ||
types: | ||
css: true | ||
js: true | ||
``` | ||
#### Exclude files | ||
```yaml | ||
# config/packages/sensiolabs_minify.yaml | ||
sensiolabs_minify: | ||
asset_mapper: | ||
|
||
# Exclude files | ||
ignore_paths: | ||
- 'admin/*' | ||
- '*.min.js' | ||
# Exclude vendor assets | ||
ignore_vendor: true | ||
``` | ||
### Minify Binary | ||
#### Local binary | ||
```yaml | ||
# config/packages/sensiolabs_minify.yaml | ||
sensiolabs_minify: | ||
minify: | ||
# Auto-detect the local binary | ||
local_binary: 'auto' | ||
|
||
# Specify the local binary path | ||
# local_binary: "/usr/local/sbin/minify" | ||
# Or set false to disable | ||
# local_binary: false | ||
``` | ||
|
||
#### Automatic download | ||
|
||
```yaml | ||
# config/packages/sensiolabs_minify.yaml | ||
sensiolabs_minify: | ||
minify: | ||
|
||
# Enable automatic download from GitHub | ||
download_binary: true | ||
# Directory to store the downloaded binary | ||
download_directory: '%kernel.project_dir%/var/minify' | ||
|
||
``` | ||
|
||
## Console | ||
|
||
### Command Line | ||
|
||
#### Install Minify locally | ||
|
||
```shell | ||
php bin/console minify:install | ||
``` | ||
|
||
#### Minify assets | ||
|
||
```shell | ||
php bin/console minify:assets css/main.css css/main.min.css | ||
``` | ||
|
||
## Credits | ||
|
||
- Minify binary: [Timo Dewolf](https://github.com/tdewolff) | ||
- Symfony Bundle: [Simon André](https://github.com/smnandre) & [SensioLabs](https://github.com/sensiolabs) | ||
|
||
## License | ||
|
||
The [SensioLabs Minify Bundle](https://github.com/sensiolabs/minify-bundle) is released under the [MIT license](LICENSE). | ||
|
||
|
||
[1]: https://cdn.jsdelivr.net/npm/@tarekraafat/[email protected]/dist/autoComplete.js | ||
[3]: https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.js | ||
[5]: https://cdn.jsdelivr.net/npm/[email protected]/dist/video.js | ||
[7]: https://github.com/w3c/w3c-website-templates-bundle/blob/main/public/dist/assets/js/main.js | ||
[2]: https://cdn.jsdelivr.net/npm/@tarekraafat/[email protected]/dist/css/autoComplete.css | ||
[4]: https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.css | ||
[6]: https://cdn.jsdelivr.net/npm/[email protected]/dist/video-js.css | ||
[8]: https://github.com/w3c/w3c-website-templates-bundle/blob/main/public/dist/assets/styles/core.css |
Oops, something went wrong.