Minification is not working (CssMin, JsMin) #151

Open
Marwelln opened this Issue Jun 6, 2013 · 16 comments

Comments

Projects
None yet
7 participants
@Marwelln

Marwelln commented Jun 6, 2013

Just as #65, using ->apply('CssMin') is not working.

In my config.php file I have this collections array:
'collections' => array(
'application' => function($collection) {
$directory = $collection->directory('assets/css', function($collection) {
$collection->requireDirectory();
});

            $directory->apply('CssMin');
            $directory->apply('UriRewriteFilter');

            $directory = $collection->directory('assets/js', function($collection) {
                $collection->requireDirectory('transactions')->apply('JsMin');
                $collection->requireDirectory('user')->apply('JsMin');
                $collection->requireDirectory();
            });

            $directory->apply('JsMin');
        }
    ),

Then I run this artisan command:
php artisan basset:build application

It builds fine, but the problem is that the output is not minified.

@jasonlewis

This comment has been minimized.

Show comment
Hide comment
@jasonlewis

jasonlewis Jun 6, 2013

Owner

Hm, my guess is it's not building because the environment isn't production. This probably isn't ideal. If you look at the alias for CssMin it uses whenEnvironmentIs('production', 'prod') which means only when your application is running on that environment will it apply.

I might add a requirement like whenProductionBuild or whenDevelopmentBuild to only apply during a production or development build. Fix coming shortly.

Owner

jasonlewis commented Jun 6, 2013

Hm, my guess is it's not building because the environment isn't production. This probably isn't ideal. If you look at the alias for CssMin it uses whenEnvironmentIs('production', 'prod') which means only when your application is running on that environment will it apply.

I might add a requirement like whenProductionBuild or whenDevelopmentBuild to only apply during a production or development build. Fix coming shortly.

@Marwelln

This comment has been minimized.

Show comment
Hide comment
@Marwelln

Marwelln Jun 6, 2013

I changed my environment between local and production, none are minimizing the files.

Marwelln commented Jun 6, 2013

I changed my environment between local and production, none are minimizing the files.

@jasonlewis

This comment has been minimized.

Show comment
Hide comment
@jasonlewis

jasonlewis Jun 6, 2013

Owner

You'd need to remove the whenEnvironmentIs requirement from the CssMin filter alias.

Owner

jasonlewis commented Jun 6, 2013

You'd need to remove the whenEnvironmentIs requirement from the CssMin filter alias.

@Marwelln

This comment has been minimized.

Show comment
Hide comment
@Marwelln

Marwelln Jun 6, 2013

Removing it did nothing. I deleted the previous builds and ran the command again, but it's still not minimized.

'CssMin' => array('CssMinFilter', function($filter) { $filter->whenClassExists('CssMin'); }),

This in the config.php file.

PS. I'm on Windows 7.

Marwelln commented Jun 6, 2013

Removing it did nothing. I deleted the previous builds and ran the command again, but it's still not minimized.

'CssMin' => array('CssMinFilter', function($filter) { $filter->whenClassExists('CssMin'); }),

This in the config.php file.

PS. I'm on Windows 7.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 7, 2013

How are you loading CssMin and JSMin? Have you seen:
http://jasonlewis.me/code/basset/4.0/filters#windows-compatibility

ghost commented Jun 7, 2013

How are you loading CssMin and JSMin? Have you seen:
http://jasonlewis.me/code/basset/4.0/filters#windows-compatibility

@jasonlewis

This comment has been minimized.

Show comment
Hide comment
@jasonlewis

jasonlewis Jun 7, 2013

Owner

I've pushed out a fix that may or may not solve your issue. The config file has been updated to include to changes.

There are now whenProductionBuild and whenDevelopmentBuild requirements available for filters. So the filter will only be applied to either of the builds. The config has been updated so that CssMin and JsMin are only applied when it's a production build.

Now, make sure you have the CssMin library downloaded and autoloaded with Laravel. If you want Composer to manage it all then add a repositories key to your composer.json like so:

"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" ] }
        }
    }
],

Then in your requires key:

"cssmin/cssmin": "3.0.*"

You should now be able to use the CssMin filter.

Owner

jasonlewis commented Jun 7, 2013

I've pushed out a fix that may or may not solve your issue. The config file has been updated to include to changes.

There are now whenProductionBuild and whenDevelopmentBuild requirements available for filters. So the filter will only be applied to either of the builds. The config has been updated so that CssMin and JsMin are only applied when it's a production build.

Now, make sure you have the CssMin library downloaded and autoloaded with Laravel. If you want Composer to manage it all then add a repositories key to your composer.json like so:

"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" ] }
        }
    }
],

Then in your requires key:

"cssmin/cssmin": "3.0.*"

You should now be able to use the CssMin filter.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 7, 2013

He shouldn't have to modify his composer.json. CSSmin is a required repo in Assetic.

ghost commented Jun 7, 2013

He shouldn't have to modify his composer.json. CSSmin is a required repo in Assetic.

@jasonlewis

This comment has been minimized.

Show comment
Hide comment
@jasonlewis

jasonlewis Jun 7, 2013

Owner

It's a dev dependency.

Owner

jasonlewis commented Jun 7, 2013

It's a dev dependency.

@raffjones

This comment has been minimized.

Show comment
Hide comment
@raffjones

raffjones Jun 14, 2013

I am struggling with this too. I've added CssMin via composer as suggested by Jason, and also removed the requirement for a production build from my Basset config file, but this just won't work:

Basset::collection('bootstrap', function($collection)
{
    $collection->add('assets/css/less/bootstrap-custom.less');
})->apply('Less')->andApply('CssMin');

I can see cssmin in both node_modules in my application root (I installed via node rpm) and also now in vendor/cssmin.

I have verified by class_exists('CssMin') that the CssMin class does exist.

Removing ->andApply('CssMin') from the filter chain triggers a build. But adding it back in gives Stylesheets build was not required for collection. when I run the artisan build command.

Any idea what's up?

(and thanks for Basset - I love it, with this minor glitch sorted it will be my asset publishing dream realised!)

I am struggling with this too. I've added CssMin via composer as suggested by Jason, and also removed the requirement for a production build from my Basset config file, but this just won't work:

Basset::collection('bootstrap', function($collection)
{
    $collection->add('assets/css/less/bootstrap-custom.less');
})->apply('Less')->andApply('CssMin');

I can see cssmin in both node_modules in my application root (I installed via node rpm) and also now in vendor/cssmin.

I have verified by class_exists('CssMin') that the CssMin class does exist.

Removing ->andApply('CssMin') from the filter chain triggers a build. But adding it back in gives Stylesheets build was not required for collection. when I run the artisan build command.

Any idea what's up?

(and thanks for Basset - I love it, with this minor glitch sorted it will be my asset publishing dream realised!)

@raffjones

This comment has been minimized.

Show comment
Hide comment
@raffjones

raffjones Jun 14, 2013

Just a follow up...

Adding the --production flag to the Artisan build command sorts this out in my case.

Just a follow up...

Adding the --production flag to the Artisan build command sorts this out in my case.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 14, 2013

@raffjones if you look at the filter definition for CSSmin around line 234 in the config.php, you will see that whenProductionBuild() returns true is when CSSmin is actually applied. Same goes for JSmin

ghost commented Jun 14, 2013

@raffjones if you look at the filter definition for CSSmin around line 234 in the config.php, you will see that whenProductionBuild() returns true is when CSSmin is actually applied. Same goes for JSmin

@dvdkruk

This comment has been minimized.

Show comment
Hide comment
@dvdkruk

dvdkruk Jun 18, 2013

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

dvdkruk commented Jun 18, 2013

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

@envision

This comment has been minimized.

Show comment
Hide comment
@envision

envision Jun 22, 2013

I have the same problem. I composer installed CSSmin and it does minification now but with a weird problem: the styles aren't applied even the css file is ok and firebug shows all the style declarations there, but not on any elements.

But the main problem here is that when CSSmin and JSmin are included in Assetic, they aren't loaded for some reason?

I have the same problem. I composer installed CSSmin and it does minification now but with a weird problem: the styles aren't applied even the css file is ok and firebug shows all the style declarations there, but not on any elements.

But the main problem here is that when CSSmin and JSmin are included in Assetic, they aren't loaded for some reason?

@barryvdh

This comment has been minimized.

Show comment
Hide comment
@barryvdh

barryvdh Sep 19, 2013

Can't you just add https://packagist.org/packages/natxet/CssMin instead (packagist clone of the google repo). Assetic doesn't just download all the filters, because it doesn't know that filters you are going to use..

Can't you just add https://packagist.org/packages/natxet/CssMin instead (packagist clone of the google repo). Assetic doesn't just download all the filters, because it doesn't know that filters you are going to use..

@envision

This comment has been minimized.

Show comment
Hide comment
@envision

envision Sep 19, 2013

@barryvdh I have mrclay/minify installed which seems to work with JS but not with CSS - weird? How does Basset know which libraries are there and how it chooses which to use?

@jasonlewis I'm also having a weird issue with debugging... When I have defined environment as 'local' and added that to Basset configs production environment array, neither minification nor combining of files are happening. Issue persists also if I have set 'production' key in $app->detectEnvironment array to 'projectname.local' (my working MAMP host) and dd($env) right after to verify set environment.

On the real production environment all is running ok except for the CSS minification not happening with mrclay/minify installed - do I need to config that somewhere?

Addition: Could mrclay/minify intervene with Assetic's required cssmin/cssmin? Though before I added mrclay/minify neither CSS nor JS minification was happening.

@barryvdh I have mrclay/minify installed which seems to work with JS but not with CSS - weird? How does Basset know which libraries are there and how it chooses which to use?

@jasonlewis I'm also having a weird issue with debugging... When I have defined environment as 'local' and added that to Basset configs production environment array, neither minification nor combining of files are happening. Issue persists also if I have set 'production' key in $app->detectEnvironment array to 'projectname.local' (my working MAMP host) and dd($env) right after to verify set environment.

On the real production environment all is running ok except for the CSS minification not happening with mrclay/minify installed - do I need to config that somewhere?

Addition: Could mrclay/minify intervene with Assetic's required cssmin/cssmin? Though before I added mrclay/minify neither CSS nor JS minification was happening.

@barryvdh

This comment has been minimized.

Show comment
Hide comment
@barryvdh

barryvdh Sep 19, 2013

It uses mrclay for js, not for css. Depends in the filter. You can write your own filter if you want, like this https://github.com/barryvdh/assetic-filters/blob/master/src/CSSminFilter.php

It uses mrclay for js, not for css. Depends in the filter. You can write your own filter if you want, like this https://github.com/barryvdh/assetic-filters/blob/master/src/CSSminFilter.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment