-
Notifications
You must be signed in to change notification settings - Fork 7
Command line interface
From a command prompt, you can invoke the PhpMinifier
executable by using
the npx
command:
$ npx @cedx/php-minifier --help
Minify PHP source code by removing comments and whitespace.
Usage:
npx @cedx/php-minifier [options] <input> [output]
Arguments:
input The path to the input directory.
output The path to the output directory.
Options:
-b, --binary The path to the PHP executable. Defaults to "php".
-e, --extension The extension of the PHP files to process. Defaults to "php".
-m, --mode The operation mode of the minifier. Defaults to "safe".
-r, --recursive Whether to process the input directory recursively.
-s, --silent Whether to silence the minifier output.
-h, --help Display this help.
-v, --version Output the version number.
For example:
npx @cedx/php-minifier path/to/source/folder path/to/destination/folder
# Minifying: MyClass1.php
# Minifying: subfolder/MyClass2.php
# ...
The minifier relies on the availability of the PHP executable on the target system. By default, the minifier will use the php
binary found on the system path.
If the minifier cannot find the default php
binary, or if you want to use a different one, you can provide the path to the php
executable by using the binary
option:
npx @cedx/php-minifier "--binary=C:\Program Files\PHP\php.exe" path/to/source/folder
By default, the minifier will process all files with the .php
extension. If your PHP scripts use a different file extension, you can specify another extension to process by using the extension
option:
npx @cedx/php-minifier --extension=php8 path/to/source/folder
The minifier can work in two manners, which can be selected using the mode
option:
- the
safe
mode: as its name implies, this mode is very reliable. But it is also very slow as it spawns a new PHP process for every file to be processed. This is the default mode. - the
fast
mode: as its name implies, this mode is very fast, but it is not always reliable. It spawns a PHP web server that processes the input files, but on some systems this fails.
npx @cedx/php-minifier --mode=fast path/to/source/folder
Tip
The command line defaults to the safe
mode, but you should really give a try to the fast
one.
The difference is very noticeable.
By default, the minifier will only process files located at the root of the input folder. To also process all subfolders and files recursively, set the recursive
option:
npx @cedx/php-minifier --recursive path/to/source/folder
By default, the minifier prints to the standard output the paths of the minified scripts. You can disable this output by setting the silent
option:
npx @cedx/php-minifier --silent path/to/source/folder