matthiasmullie / minify

CSS & JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.
https://matthiasmullie.github.io/minify/
MIT License
1.96k stars 310 forks source link

Revamp the CLI bin and add documentation to the readme #388

Open kodie opened 2 years ago

kodie commented 2 years ago

I'm using this package for a few different projects and I didn't even realize that there was an included CLI tool.

However, I needed the CLI tool to actually create the files rather than just echo the minified contents to STDOUT, so this led me to revamp the CLI tool.

This PR does a few things:

  1. Combines the minifycss and minifyjs commands into a single minify command (A breaking change for anyone currently using the CLI tool).
  2. Adds the ability to define an --ouput or -o option to have the minified contents written to a file (And if no output is defined, it'll echo the minified contents to STDOUT just like before).
  3. Adds the ability for multiple input files to be minified into each of their own output files (ex. -o "/path/to/minified/*.min.js")
  4. Adds the --import-ext, --gzip, and --max-import-size options to be able to use those features with the CLI tool.
  5. Adds the ability to pass multiple input files to be combined and minified together.
  6. Adds documentation about the CLI tool to the readme.
  7. Adds a help option to the CLI tool.

So now, you can do something like this:

bin/minify tests/js/sample/source/*.js -o test.js tests/css/sample/convert_relative_path/source/*.css -o test.css

and you'll end up with a test.js and test.css file.

This will come in handy as a dev tool for projects. For example, I could add a build script to the composer.json file of my package:

{
  "scripts": {
    "build": "vendor/bin/minify source1.js source2.js -o build.min.js"
  },
  "require-dev": {
    "matthiasmullie/minify": "^1.3.63"
  }
}

What's also nice about this is that other than swapping out the minifycss and minifyjs commands for minify it'll still function exactly the same as before unless you specifically decide to use some of the newly added options.