Search code examples
csssymfonysasscompass-sassassetic

Symfony 2.7 + Sass + Assetic does not create any styles or files


I would like to use Sass based styles in my Symfony 2.7 WebApp. So far I have used Compass to compile Sass files (located not in the web/ dir but within the Bundles) to CSS files. This works fine, but on a new server Ruby is not available and thus Compass is not an option anymore.

Following the Symfony Docu, I have added leafo/scssphp to the project and activated in the config file:

# app/config/config.yml
assetic:
    filters:
        scssphp:
            formatter: 'Leafo\ScssPhp\Formatter\Compressed'
        # ...

The Sass files within the Twig templates:

{% stylesheets 
    'MyMainBundle/Resources/styles/sass/header.scss'
    filter="scssphp" 
    output="css/header.css" %}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

When using the debug front controller app_dev.php a page refresh shows, that the header.css is correctly link, but the linked file is empty.

The header.scss contains pure Sass (no Compass function), the path is correct and no error is displayed. So, why is the header.css empty?

Dumping the assets instead of using app_dev.php does not solve the problem as well. The console shows all assets that are created during the dump, but not any sign of the header.css

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

I tried different other possibilits to specifiy the path of the header.scss, but the result is always the same. Only using the @Bundle notation results in an NotFoundException.

{% stylesheets 
    '@MyMainBundle/Resources/sass/header.scss'
    ...

It does not make any difference if the Sass files are located inside a bundle directory or inside the web/ folder (as described in the Symfony docs).

So: How to integrate the Sass file directly into Symfony by using Assetic?


Solution

  • I solved the problem. Maybe the solution is useful for others as well:

    My AsseticBundle / Assetic version was outdated. After updated to the latest version everything works fine.