PHPackages                             devize/closure-compiler - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. devize/closure-compiler

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

devize/closure-compiler
=======================

Google's Closure Compiler for use in PHP-based projects

156.7k3[1 issues](https://github.com/devize/closure-compiler/issues)PHP

Since May 21Pushed 11y ago2 watchersCompare

[ Source](https://github.com/devize/closure-compiler)[ Packagist](https://packagist.org/packages/devize/closure-compiler)[ RSS](/packages/devize-closure-compiler/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Closure Compiler
================

[](#closure-compiler)

What is the Closure Compiler?
-----------------------------

[](#what-is-the-closure-compiler)

From [Google](https://developers.google.com/closure/compiler/):

> The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.

Why does this library exist?
----------------------------

[](#why-does-this-library-exist)

The Closure Compiler (CC), as provided by Google, is available as a web application or for download as a commandline Java jarfile. This file can be used to run your own compilations. However, to use the compiler this way, you must type (or paste) all your javascript filenames into a terminal window, which can be cumbersome and is not easy to automate.

This library provides a PHP wrapper around the CC which can be used in PHP scripts. Using the wrapper, you can connect the configuration of your PHP application to the compiler and automate your compilations. Your compilation build script can then be used in, for instance, a Phing script.

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

[](#installation)

Clone this repository and include the classes. Or use Composer:

```
"require-dev": {
    "devize/closure-compiler": "*"
}

```

The library uses Composer's autoloader so if your application uses it as well, you don't have to do anything else.

Usage
-----

[](#usage)

Assuming you have managed your own autoloader, set your own includes or are using Composer's autoloader:

```
use Devize\ClosureCompiler\ClosureCompiler;
$compiler = new ClosureCompiler;
$compiler->setSourceBaseDir('path/to/javascript-files/');
$compiler->setTargetBaseDir('path/to/javascript-files/');
$compiler->setSourceFiles(array('one.js', 'two.js', 'three.js'));
$compiler->addSourceFile('four');
$result = $compiler->compile();
if ($result !== 0) {
	echo $compiler->getOutput();
}

```

The `compile()` method uses a system call to execute the Jar-file. By default, the resulting file is called `compiled.js`. You can change this by calling this before you compile:

```
$compiler->setTargetFile('somethingElse.js');

```

When you make a mistake, an exception of the class `Devize\ClosureCompiler\CompilerException` will be thrown.

License
-------

[](#license)

This library packages the Closure Compiler from Google. The folder `compiler-latest` is the result of unpacking the Google-supplied [Zip file](http://closure-compiler.googlecode.com/files/compiler-latest.zip). Its license is included.

The PHP wrapper files are licensed under the MIT license.

Feedback
--------

[](#feedback)

Any feedback is welcome; use the Github system or send a tweet to @breuls.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6364c4564d715c729971baa827648629d3ee735123dfa1ed52ff20746ff2f427?d=identicon)[Breuls](/maintainers/Breuls)

---

Top Contributors

[![Breuls](https://avatars.githubusercontent.com/u/1822037?v=4)](https://github.com/Breuls "Breuls (8 commits)")[![dappvibe](https://avatars.githubusercontent.com/u/57523522?v=4)](https://github.com/dappvibe "dappvibe (1 commits)")

### Embed Badge

![Health badge](/badges/devize-closure-compiler/health.svg)

```
[![Health](https://phpackages.com/badges/devize-closure-compiler/health.svg)](https://phpackages.com/packages/devize-closure-compiler)
```

###  Alternatives

[log1x/gutentweaks

A plugin containing minor Gutenberg tweaks.

113.9k](/packages/log1x-gutentweaks)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
