Question

I used this guide to adding the yui_compressor to my symfony project. But its not creating the minified files. Below are the settings I applied, please take a look and tell me what might be going wrong. Config File

// Added this to the config.yml file in app/config (and yes, I'm on a mac)  
    yui_css:
        jar: "%kernel.root_dir%/Resources/filter/java/yuicompressor-2.4.7.jar"
        java: /usr/bin/java

Base Twig

// Added this to the :base.html.twig in app/Resources/views

    {% stylesheets  filter='yui_css' output='public/css/compiled-main.css'
        'public/css/main.css'
    %}

Added the file in the yui_compressor zip file under build to the app/Resources/filter/java folder in my symfony project

Était-ce utile?

La solution

1 - Download and add yuicompressor to your project

Unzip, go to build/ dir and extract yuicompressor-2.4.7.jar to put it in your app/Resources/java/ project dir. (In addition, you can rename yui file for yuicompressor.jar)

2 - Enable yui compression for prod environement

This is logical to add yui compressor in your config_prod.yml file and not for all environment (you should remove lines from config.yml).

So add theses lines in config_prod.yml:

assetic:
    debug: false
    filters:
        yui_js:
            jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
            apply_to: "\.js"
        yui_css:
            jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
            apply_to: "\.css"

3 - Verify you prod controller file

Go to web/app.php, and set prod / false (false for no debug).

$kernel = new AppKernel('prod', false);

4 - Clear cache

If you want to rebuild your CSS and JS (after update), never forget to clear cache in prod otherwise modifications will be ignored by yui compressor:

php app/console cache:clear --env=prod --no-debug

5 - Regenerate fixtures with compression

Finally, you can generate and compress your files !

php app/console assetic:dump --env=prod --no-debug -v

Note that -v show more details about the process of compression, you will be able to see if there is an error taht causes problems with yui compressor !

For example, the JS comment tag "/!" causes trouble with yui compressor, you should rename all "/!" for "/*" in your JS files.

That's it ^^

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top