JS Minify and CSS Minify with Basset
Sep 17, 2013  

I can be really slow at times and I'm not afraid to admit it. I don't want to start there though, I'd rather start with some praises about Basset and how much time it has saved me. If you don't know, Basset is an asset management package by Jason Lewis. (seriously, who doesn't know this?) Anyway, it's great, BUT for the life of me I couldn't figure out why CSS minify wouldn't work until I bothered to browse the issues on the github repo. Now, we're getting back to me being slow. So this brings us to issue #151.

The Problem

The problem in my case is that the nested composer.json of <code>kriswallsmith/assetic isn't executed when using composer install from the root. Therefore no dependencies are loaded/installed and so nothing is compressed.

That's right and it also doesn't do any justice for composer update.

The Fix

The fix is fairly simple, just let composer manage them for you and auto load with Laravel. I've mocked up what has to be added for both CSS and JS minification (that's a word).

In your require key

"cssmin/cssmin": "*",
"mrclay/minify": "*"

Then add a repositories key

"repositories": [
{
    "type": "package",
    "package": {
        "name": "cssmin/cssmin",
        "version": "3.0.1",
        "dist": { "url": "http://cssmin.googlecode.com/files/cssmin-v3.0.1.php", "type": "file" },
        "autoload": { "classmap": [ "cssmin-v3.0.1.php" ] }
    }
}
],

Overall Example

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "require": {
        "laravel/framework": "4.0.*",
        "jasonlewis/basset": "dev-master",
        "cssmin/cssmin": "*",
        "mrclay/minify": "*" 
        },
        "repositories": [
        {
            "type": "package",
            "package": {
                "name": "cssmin/cssmin",
                "version": "3.0.1",
                "dist": { "url": "http://cssmin.googlecode.com/files/cssmin-v3.0.1.php", "type": "file" },
                "autoload": { "classmap": [ "cssmin-v3.0.1.php" ] }
            }
        }
        ],

Now you can just composer update and <code>php artisan basset:build --production at will :)