Symfony Assetic, Lesscss and cssrewrite

349 views Asked by At

I work with Symfony 2.7, Assetic and LessCss. In dev environment, my configuration works well. All css are generated and images are embeded in base64. But when I try to compile LessCss for prod environment with php app/console assetic:dump --env=prod, cssembed crash because he doesn't found images.

Here my folder structure :

app
├── config
├── Resources
│   ├── less
│   │   ├── base.less
src
web
├── bundles
├── ui
│   ├── some-images.png

My config.yml

# Assetic Configuration
assetic:
    debug: "%kernel.debug%"
    use_controller: false
    bundles:
        - CnertaTutoPrestoBundle
    #java: /usr/bin/java
    filters:
        less:
            node: /usr/bin/node
            node_paths: [/usr/lib/node_modules]
            apply_to: "\.less$"
        cssembed:
            jar: %kernel.root_dir%/../vendor/scribe/cssembed-library/dist/cssembed.jar
        cssrewrite: ~
    assets:
        base_style:
            inputs:
                - %kernel.root_dir%/Resources/less/base.less
            filters:
                - less
                - cssrewrite
                - cssembed

My base.less

@pathWeb:           "/../../../../web/ui/";
.user{
    background-image: url("@{pathWeb}image.png");
}

The weird thing is that if I change "/../../../../web/ui/" for "/../../../web/ui/" (I've just removed a “../”), I can compile Css for prod environment. But the LessCss dosen't work anymore for dev environment.

I really do not know from where comes my problem.

2

There are 2 answers

1
FZE On

Did you checked your config_dev.yml file ? may there be a configuration which conflicts with your config.yml.

I had some problems with assetic before, smiliar to your problem. Check

Assetic Configuration

assetic: use_controller : true or false

http://symfony.com/doc/current/cookbook/assetic/asset_management.html#dumping-asset-files-in-the-dev-environment

In my application everything is well now. In config.yml use_controller: false in config_dev.yml use_controller is true.

0
Waldo On

Well, well, well,

The problem come from cssrewrite. If I don't use it and I change my image path with "../../../web/ui/" all works fine. In dev and prod environment.