PHPackages                             fivefifteen/piler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. fivefifteen/piler

ActiveLibrary[File &amp; Storage](/categories/file-storage)

fivefifteen/piler
=================

A CLI tool written in PHP that compiles and minifies JavaScript and CSS/SCSS files.

0.1.2(2mo ago)2536[1 issues](https://github.com/fivefifteen/piler/issues)1MITPHPPHP ^8.1

Since Dec 2Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/fivefifteen/piler)[ Packagist](https://packagist.org/packages/fivefifteen/piler)[ Docs](https://github.com/fivefifteen/piler)[ RSS](/packages/fivefifteen-piler/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependencies (8)Versions (8)Used By (1)

[![Piler](./assets/piler.png)](./assets/piler.png)

Piler
=====

[](#piler)

A CLI tool written in PHP that compiles and minifies JavaScript and CSS/SCSS files.

[![packagist package version](https://camo.githubusercontent.com/79dec6e8fccee4f681fdc9829eda6be14ac3a293bd0d720f62c51184d2779029/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666976656669667465656e2f70696c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fivefifteen/piler)[![packagist package downloads](https://camo.githubusercontent.com/5b526a7b438217f1bc9e136923fc8a87a0d20e322a4d91eefdd4e6c12491a482/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666976656669667465656e2f70696c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fivefifteen/piler)[![GitHub code size in bytes](https://camo.githubusercontent.com/3c89fde469f6331a5216c5132a02d7b9f303724ef81c4f23cc8a28e4f0ab5352/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f666976656669667465656e2f70696c65723f7374796c653d666c61742d737175617265)](https://github.com/fivefifteen/piler)[![license](https://camo.githubusercontent.com/0221d142b1a9d2dcf26121e48f540995f94fa307f8430ecd32a4373597810d26/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f666976656669667465656e2f70696c65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/fivefifteen/piler/blob/main/license.md)

[![](https://camo.githubusercontent.com/1923e75a3b7f914e065708967335398c9a71c4df3e13ee1082a2d4ef8ccd2e3d/68747470733a2f2f61736369696e656d612e6f72672f612f3639333234332e737667)](https://asciinema.org/a/693243)

[![](./assets/fivefifteen.png)
**A Five Fifteen Project**](https://fivefifteen.com)

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)
    - [Configuration via Composer](#configuration-via-composer)
    - [Hot-Reloading](#hot-reloading)
- [Related Projects](#related-projects)
- [License Information](#license-information)

Requirements
------------

[](#requirements)

- PHP 8.1 or above
- Composer

Installation
------------

[](#installation)

### To a package (local)

[](#to-a-package-local)

```
composer require-dev fivefifteen/piler
./vendor/bin/piler --version

```

### To your system (global)

[](#to-your-system-global)

```
composer global require fivefifteen/piler
piler --version
```

Usage
-----

[](#usage)

```
piler [options...] [input...]
```

##### Options

[](#options)

- `[-n|--bail-on-overwrite]` - Skips the confirmation prompt and bails if a file already exists in the output directory (takes priority over -y)
- `[-c|--config]` - Path to a config JSON file \[default: `pile.json`\]
- `[-d|--dry-run]` - Don't actually write anything so that you can test the command
- `[-e|--event-source]` - Server accessible path to point EventSource to for hot-reloading (JS required)
- `[-h|--help]` - Show help
- `[-i|--ignore-errors]` - Ignore any errors that may occur and continue processing as much as possible
- `[-p|--import-path...]` - Additional directory path(s) to import from (`fetched` directory added by default for built-in [Fetcher](https://github.com/fivefifteen/fetcher) support)
- `[-m|--no-minify]` - Minfy files \[default: `true`\]
- `[-o|--output...]` - The directory path(s) or filename(s) to write to
- `[-q|--quiet]` - Run but don't output anything in the terminal
- `[-s|--save]` - Save list of compiled files to pile.json to easily run again later
- `[-v|--verbosity]` - Verbosity level \[default: `0`\]
- `[-V|--version]` - Show version
- `[-W|--watch]` - Monitor defined files for changes and re-process when they are changed (enables -y)
- `[-w|--working-directory]` - Sets the working directory that all paths will be relative to \[default: `.`\]
- `[-y|--yes-to-overwrite]` - Skips the confirmation prompt and overwrites files if they already exist in the output directory

##### Examples

[](#examples)

```
# Process files listed in the `compile` section of a custom config file
piler --config content/themes/my-theme/compile.json

# Minify all .js files in the `scripts` directory (minified files will be saved as *.min.js in the scripts directory)
piler scripts/*.js

# Minify all .js files in the `scripts` directory and save the minified files to the build directory
piler scripts/*.js --output build

# Minify all .js files in the `scripts` directory and save the minified files with a customized prefix to the build directory
piler scripts/*.js --output build/compiled-{name}.min.js

# Compile all .scss files in the `styles` directory to minified css (minified files will be saved as *.min.css in the styles directory)
piler styles/*.scss

# Compile all .scss files in the `styles` directory to minified css and save the files to the build directory
piler styles/*.scss --output build

# Compile all .scss and .css files in the `styles` directory to minified css and save the files with a customized prefix to the build directory
piler styles/*.{scss,css} --output build/compiled-{name}.min.css
piler styles/*.{scss,css} scripts/*.js -o build/compiled-{name}.min.css # same as above since output is specifically set to .css so .js files will be ignored

# Minify all .js files in the `scripts` directory and compile all .scss and .css files in the `styles` directory, put all minified .js and .css files in the build directory with a custom prefix
piler styles/*.{scss,css} scripts/*.js --output build/compiled-{name}.min.{ext}
piler styles/*.{scss,css} scripts/*.js --output build/compiled-{name}.min.css --output build/compiled-{name}.min.js # same as above
piler styles/*.{scss,css} scripts/*.js -o build/compiled-{name}.min.css -o build/compiled-{name}.min.js # same as above

# Concat and minify all .js files in the `scripts` directory and concat and compile all .scss and .css files in the `styles` directory, put all minified .js and .css files in the build directory with a custom prefix (when concat option is used, {name} will become 'script' for js and 'style' for css. use {names} for plural)
piler styles/*.{scss,css} scripts/*.js --output build/compiled-{name}.min.{ext} # will end up with a compiled-script.min.js and a compiled-style.min.css
piler styles/*.{scss,css} scripts/*.js -o build/compiled-script.min.js -o build/compiled-style.min.js # same as above
piler styles/*.{scss,css} scripts/*.js --output build/compiled-{names}.min.{ext} # will end up with a compiled-scripts.min.js and a compiled-styles.min.css
piler styles/*.{scss,css} scripts/*.js -o build/compiled-scripts.min.js -o build/compiled-styles.min.js # same as above

# Concat and minify all .js files in the `scripts/src` and `scripts/vendor` directories into one minified .js file in the build directory
piler scripts/src/*.js scripts/vendor/*.js -o build/compiled-scripts.min.js

# Concat and minify all .js files in the `scripts/src` and `scripts/vendor` directories into two minified .js files in the build directory
piler scripts/src/*.js scripts/vendor/*.js -o build/compiled-scripts.min.js -o build/vendor-scripts.min.js
```

Configuration
-------------

[](#configuration)

While Piler can be used out of the box without any configuration, a config file allows for better customization and easier package management.

```
{
  "piler": {
    "config": {
      "config_path": "compile.json",
      "event_source": "/reloader.php",
      "import_paths": ["fetched"],
      "minify": true,
      "yes_to_overwrite": true
    },
    "compile": {
      "style.css": "scss/style.scss",
      "js/scripts.min.js": [
        "bluzky/nice-select2/dist/js/nice-select2.js",
        "js/src/*.js"
      ]
    }
  }
}
```

### Configuration via Composer

[](#configuration-via-composer)

Piler also supports loading configuration options from a `composer.json` file, except for in this case Piler checks for it's key under the `extra` section like so:

```
{
  "name": "username/package",
  "version": "0.0.1",
  "require-dev": {
    "fivefifteen/piler": "*"
  },
  "scripts": {
    "build": "./vendor/bin/piler -y"
  },
  "extra": {
    "piler": {
      "config": {
        "config_path": "compile.json",
        "event_source": "/reloader.php",
        "import_paths": ["fetched"],
        "minify": true,
        "yes_to_overwrite": true
      },
      "compile": {
        "style.css": "scss/style.scss",
        "js/scripts.min.js": [
          "bluzky/nice-select2/dist/js/nice-select2.js",
          "js/src/*.js"
        ]
      }
    }
  }
}
```

### Hot-Reloading

[](#hot-reloading)

Piler can be configured to automatically reload your page whenever you make changes to your compiled files. This works by injecting a small piece of JavaScript into your code (which means at least one compiled JavaScript file is required).

To set this up, create a `reloader.php` file somewhere accessible by the front-end of your website and place the following contents in there:

```
