Symfony2 assetic:dump wrong write_to path

2019-09-08 19:31发布

问题:

I have a longtime problem with assetic:dump. I wanna use "assetic" to get Javascript and CSS files from different bundles (I wrote) and collect them to dev and prod environment in the templates. Everytime I wanna dump new files, the assetic:dump command try to write in a complete broken path.

app/console assetic:dump

  [RuntimeException]                                                                                       
  Unable to create directory /var/www/app/../web//var/www/app/../htdocs/css  

I also try writing in: (nothing works)

app/console assetic:dump web
app/console assetic:dump .
app/console assetic:dump /var/www/web

I configured assetic like this:

assetic:
    debug:          %kernel.debug%
    use_controller: false
    read_from: "%kernel.root_dir%/../web"
    write_to: "%kernel.root_dir%/../web"
    bundles:
      - MyCodeBundle
      - NextCodeBundle
    #java: /usr/bin/java
    filters:
        lessphp:
            file: %kernel.root_dir%/../vendor/oyejorge/less.php/lessc.inc.php
            apply_to: "\.less$"
        cssrewrite: ~

I use also BraincraftedBootstrapBundle to use Twitter Bootstrap Js/CSS in my templates.

Where I can fix the path of assetic:dump?

回答1:

As discussed in the comments, there seems to be a problem with the symlink from web to htdocs. Don't know if it's a bug in Symfony/Assetic or your local installation.

However, you don't even need that symlink. If you need the document root to be named htdocs, you can tell Symfony to use that directory:

In the application's composer.json, there should be an entry "symfony-web-dir": "web". Change the value to htdocs, and you should be fine. You should also remove the symlink from web to htdocs, to avoid confusion.

I haven't tested this, but I'd expect all Symfony distribution packages, including Assetic, to respect this setting. If Assetic doesn't, simply call Assetic with htdocs as target parameter.

And, you should remove the read_from and write_to parameters from your configuration. Your values are the default anyway, so there's no need to hardcode them.

Hope this helps.