Skip to content

Commit 430ff15

Browse files
committed
add docs
1 parent 5b87033 commit 430ff15

13 files changed

+308
-75
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019-2020 Michal Sniatala
3+
Copyright (c) 2019-2023 Michal Sniatala
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
# Minifier [![](https://github.com/michalsn/minifier/workflows/PHP%20Tests/badge.svg)](https://github.com/michalsn/minifier/actions?query=workflow%3A%22PHP+Tests%22)
1+
# Minifier
22

33
Asset minification and versioning library for CodeIgniter 4.
44

5+
[![PHPUnit](https://github.com/michalsn/minifier/actions/workflows/phpunit.yml/badge.svg)](https://github.com/michalsn/minifier/actions/workflows/phpunit.yml)
6+
[![PHPStan](https://github.com/michalsn/minifier/actions/workflows/phpstan.yml/badge.svg)](https://github.com/michalsn/minifier/actions/workflows/phpstan.yml)
7+
[![Deptrac](https://github.com/michalsn/minifier/actions/workflows/deptrac.yml/badge.svg)](https://github.com/michalsn/minifier/actions/workflows/deptrac.yml)
8+
[![Coverage Status](https://coveralls.io/repos/github/michalsn/minifier/badge.svg?branch=develop)](https://coveralls.io/github/michalsn/minifier?branch=develop)
9+
510
## Installation
611

7-
> composer require michalsn/minifier
12+
```console
13+
composer require michalsn/minifier
14+
```
815

916
## Configuration
1017

1118
Run command:
1219

13-
> php spark minify:publish
20+
```console
21+
php spark minify:publish
22+
```
1423

1524
This command will copy a config file to your app namespace.
1625
Then you can adjust it to your needs. By default, file will be present in `app/Config/Minifier.php`.
@@ -20,7 +29,7 @@ You should define an array of files that you want to minify, ie:
2029
```php
2130
public $js = [
2231
'all.min.js' => [
23-
'jquery-3.2.1.min.js', 'bootstrap-3.3.7.min.js', 'main.js',
32+
'jquery-3.7.1.min.js', 'bootstrap-3.3.7.min.js', 'main.js',
2433
]
2534
];
2635
```
@@ -37,71 +46,7 @@ public $css = [
3746

3847
This way requesting for a `all.min.js` or `all.min.css` file will return a minified and combined version of all files in a given array.
3948

40-
## Usage
41-
42-
To actually minify all the files we have to run command:
43-
44-
> php spark minify:all
45-
46-
This will prepare everything and will set up a versioning. Make sure to load a minifier helper in your controller, by calling:
47-
48-
```php
49-
helper('minifier');
50-
```
51-
52-
Now to generate a proper tag with desired file to load, you have to make a simple call in your code:
53-
54-
```php
55-
minifier('all.min.js');
56-
```
57-
58-
or
59-
60-
```php
61-
minifier('all.min.css');
62-
```
63-
64-
This will produce:
65-
66-
```html
67-
<script type="text/javascript" src="http://localhost/assets/js/all.min.js?v=9ef881911da8d7c4a1c2f19c4878d122"></script>
68-
```
69-
70-
or
71-
72-
```html
73-
<link rel="stylesheet" href="http://localhost/assets/css/all.min.css?v=50a35b0b1d1c3798aa556b8245314930">
74-
```
49+
## Docs
7550

76-
## Config options
77-
78-
After running command:
79-
80-
> php spark minify:publish
81-
82-
You can modify the config file which by default is copied to the path `app/Config/Minifier.php`. Here are your options with a description.
83-
84-
Variable | Default value | Options | Desctiption
85-
-------- | ------------- | ------- | -----------
86-
`$minify`| `true` | `true`, `false` | Use this variable to turn on and off minification of the assets. Turning off can be useful during app development - for easy debugging.
87-
`$baseUrl` | `null` | | Use this variable when you want to set absolute path to the asset files. If no other URLs are set, like `$baseJsUrl` or `$baseCssUrl` then values set to `$dirJS` and `$dirCss` will be added to the final URL.
88-
`$baseJsUrl` | `null` | | Use this variable when your JS assets are served from subdomain. Bare in mind that in this case variable `$dirJs` won't be added to the URL.
89-
`$baseCssUrl` | `null` | | Use this variable when your CSS assets are served from subdomain. Bare in mind that in this case variable `$dirCSS` won't be added to the URL.
90-
`$adapterJs` | `\Michalsn\Minifier\Adapters\Js\MinifyAdapter::class` | | Adapter to use for minifying JS files. You can also implement your own JS adapter to minify assets and replace this class.
91-
`$adapterCss` | `\Michalsn\Minifier\Adapters\Css\MinifyAdapter::class` | | Adapter to use for minifying CSS files. You can also implement your own CSS adapter to minify assets and replace this class.
92-
`$dirJs` | `./assets/js` | | JS assets directory.
93-
`$dirCss` | `./assets/css` | | CSS assets directory.
94-
`$dirMinJs` | `null` | | Minified JS asset directory. If not set the value from `$dirJs` will be used instead.
95-
`$dirMinCss` | `null` | | Minified CSS asset directory. If not set the value from `$dirCss` will be used instead.
96-
`$dirVersion` | `./assets` | | Directory to store assets versioning.
97-
`$tagJs` | `<script type="text/javascript" src="%s"></script>` | | JS tag to use in HTML when displaying JS assets.
98-
`$tagCss` | `<link rel="stylesheet" href="%s">` | | CSS tag to use in HTML when displaying CSS assets.
99-
`$returnType` | `html` | `html`, `json`, `array` | Determines how the files will be returned. The dafault value is `html` and it uses the `$tagJs` and `$tagCss` variables. Using `array` will return the php array and `json` type will return a json string.
100-
`$autoDeployOnChange` | `false` | `true`, `false` | Specifies if we want to automatically deploy whenever there is a change to any of our assets files. Keep in mind that enabling this feature will have an impact on performance.
101-
`$js` | | | This array defines JS files to minify.
102-
`$css` | | | This array defines CSS files to minify.
103-
104-
## License
105-
106-
The MIT License (MIT). Please see [License File](LICENSE) for more information.
51+
Read the full documentation: https://michalsn.github.io/minifier/
10752

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"homepage": "https://github.com/michalsn/minifier",
1717
"require": {
1818
"php" : "^8.1",
19-
"matthiasmullie/minify": "^1.3",
20-
"ext-json": "*"
19+
"matthiasmullie/minify": "^1.3"
2120
},
2221
"require-dev": {
2322
"codeigniter4/devkit": "^1.0",

docs/assets/favicon.ico

14.7 KB
Binary file not shown.

docs/assets/flame.svg

Lines changed: 11 additions & 0 deletions
Loading

docs/assets/github-dark-dimmed.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!
2+
Theme: GitHub Dark Dimmed
3+
Description: Dark dimmed theme as seen on github.com
4+
Author: github.com
5+
Maintainer: @Hirse
6+
Updated: 2021-05-15
7+
Modified: 2022:12:27 by @michalsn
8+
9+
Colors taken from GitHub's CSS
10+
*/.hljs{color:#adbac7 !important;background-color:#22272e !important}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#f47067}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#dcbdfb}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#6cb6ff}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#96d0ff}.hljs-built_in,.hljs-symbol{color:#f69d50}.hljs-code,.hljs-comment,.hljs-formula{color:#768390}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#8ddb8c}.hljs-subst{color:#adbac7}.hljs-section{color:#316dca;font-weight:700}.hljs-bullet{color:#eac55f}.hljs-emphasis{color:#adbac7;font-style:italic}.hljs-strong{color:#adbac7;font-weight:700}.hljs-addition{color:#b4f1b4;background-color:#1b4721}.hljs-deletion{color:#ffd8d3;background-color:#78191b}
11+
12+
[data-md-color-scheme="default"] {
13+
--md-default-fg-color--lightest: #575757;
14+
--md-default-fg-color--light: #959595;
15+
}

docs/assets/hljs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
window.document$.subscribe(() => {
2+
hljs.highlightAll();
3+
});

docs/basic-usage.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Basic Usage
2+
3+
After [defining our files](configuration.md#config-file) we want to actually minify all the files we have. This is easy enough as running the command:
4+
5+
```console
6+
php spark minify:all
7+
```
8+
9+
This will prepare everything and will set up a versioning. Make sure to load a minifier helper in your controller, by calling:
10+
11+
```php
12+
helper('minifier');
13+
```
14+
15+
Now to generate a proper tag with desired file to load, you have to make a simple call in your code:
16+
17+
```php
18+
minifier('all.min.js');
19+
```
20+
21+
or
22+
23+
```php
24+
minifier('all.min.css');
25+
```
26+
27+
This will produce:
28+
29+
```html
30+
<script type="text/javascript"
31+
src="http://localhost/assets/js/all.min.js?v=9ef881911da8d7c4a1c2f19c4878d122"></script>
32+
```
33+
34+
or
35+
36+
```html
37+
<link rel="stylesheet"
38+
href="http://localhost/assets/css/all.min.css?v=50a35b0b1d1c3798aa556b8245314930">
39+
```

docs/configuration.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Configuration
2+
3+
## Config File
4+
5+
To make changes to the config file, we have to have our copy in the `app/Config/Minifier.php`. Luckily, this package comes with handy command that will make this easy.
6+
7+
When we run:
8+
9+
```console
10+
php spark minify:publish
11+
```
12+
13+
We will get our copy ready for modifications.
14+
15+
Now, you should define an array of files that you want to minify, ie:
16+
17+
```php
18+
public $js = [
19+
'all.min.js' => [
20+
'jquery-3.7.1.min.js', 'bootstrap-3.3.7.min.js', 'main.js',
21+
]
22+
];
23+
```
24+
25+
or
26+
27+
```php
28+
public $css = [
29+
'all.min.css' => [
30+
'bootstrap-3.3.7.min.css', 'font-awesome-4.7.0.min.css', 'main.css',
31+
]
32+
];
33+
```
34+
35+
This way requesting for a `all.min.js` or `all.min.css` file will return a minified and combined version of all files in a given array.
36+
37+
## Config Options
38+
39+
### $minify
40+
41+
Use this variable to turn on and off minification of the assets. Turning off can be useful during app development - for easy debugging.
42+
43+
**Available options**: `true`, `false`
44+
45+
**Default value**: `true`
46+
47+
### $baseUrl
48+
49+
Use this variable when you want to set absolute path to the asset files. If no other URLs are set, like `$baseJsUrl` or `$baseCssUrl` then values set to `$dirJS` and `$dirCss` will be added to the final URL.
50+
51+
**Default value**: `null`
52+
53+
### $baseJsUrl
54+
55+
Use this variable when your JS assets are served from subdomain. Keep in mind that in this case variable `$dirJs` won't be added to the URL.
56+
57+
**Default value**: `null`
58+
59+
### $baseCssUrl
60+
61+
Use this variable when your CSS assets are served from subdomain. Keep in mind that in this case variable `$dirCSS` won't be added to the URL.
62+
63+
**Default value**: `null`
64+
65+
### $adapterJs
66+
67+
Adapter to use for minifying JS files. You can also implement your own JS adapter to minify assets and replace this class.
68+
69+
**Default value**: `\Michalsn\Minifier\Adapters\Js\MinifyAdapter::class`
70+
71+
### $adapterCss
72+
73+
Adapter to use for minifying CSS files. You can also implement your own CSS adapter to minify assets and replace this class.
74+
75+
**Default value**: `\Michalsn\Minifier\Adapters\Css\MinifyAdapter::class`
76+
77+
### $dirJs
78+
79+
JS assets directory.
80+
81+
**Default value**: `./assets/js`
82+
83+
### $dirCss
84+
85+
CSS assets directory.
86+
87+
**Default value**: `./assets/css`
88+
89+
### $dirMinJs
90+
91+
Minified JS asset directory. If not set the value from `$dirJs` will be used instead.
92+
93+
**Default value**: `null`
94+
95+
### $dirMinCss
96+
97+
Minified CSS asset directory. If not set the value from `$dirCss` will be used instead.
98+
99+
**Default value**: `null`
100+
101+
### $dirVersion
102+
103+
Directory to store assets versioning.
104+
105+
**Default value**: `./assets`
106+
107+
### $tagJs
108+
109+
JS tag to use in HTML when displaying JS assets.
110+
111+
**Default value**: `<script type="text/javascript" src="%s"></script>`
112+
113+
### $tagCss
114+
115+
CSS tag to use in HTML when displaying CSS assets.
116+
117+
**Default value**: `<link rel="stylesheet" href="%s">`
118+
119+
### $returnType
120+
121+
Determines how the files will be returned. The default value is `html` and it uses the `$tagJs` and `$tagCss` variables. Using `array` will return the php array and `json` type will return a json string.
122+
123+
**Available options**: `html`, `json`, `array`
124+
125+
**Default value**: `html`
126+
127+
### $autoDeployOnChange
128+
129+
Specifies if we want to automatically deploy whenever there is a change to any of our assets files. Keep in mind that enabling this feature will have an impact on performance.
130+
131+
**Available options**: `true`, `false`
132+
133+
**Default value**: `false`
134+
135+
### $js
136+
137+
This array defines JS files to minify.
138+
139+
### $css
140+
141+
This array defines CSS files to minify.

docs/index.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# CodeIgniter Minifier Documentation
2+
3+
Asset minification and versioning library for CodeIgniter 4.
4+
5+
### Requirements
6+
7+
![PHP](https://img.shields.io/badge/PHP-%5E8.1-blue)
8+
![CodeIgniter](https://img.shields.io/badge/CodeIgniter-%5E4.1-blue)
9+
10+
## Overview
11+
12+
We can define files we want to combine and minify and then use it with only one line:
13+
14+
```php
15+
echo minifier('all.min.js');
16+
// <script src="http://localhost/assets/js/all.min.js?v=9ef881911da8d7c4a1c2f19c4878d122" type="text/javascript"></script>
17+
```
18+

docs/installation.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Installation
2+
3+
## Composer Installation
4+
5+
The only thing you have to do is to run this command, and you're ready to go.
6+
7+
```console
8+
composer require michalsn/minifier
9+
```

0 commit comments

Comments
 (0)