Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assetic dump does not find uglifycss in my Symfony app

For my prod environment I want to use the UglifyCSS filter configured as follows (config_prod.yml):

assetic:
    filters:
        uglifycss:
            node: /usr/bin/env node
            bin: /usr/local/bin/uglifycss
            apply_to: "\.css$"

But whenever I run

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

I get this error message:

[Assetic\Exception\FilterException]                                                                                                                      
  An error occurred while running:                                                                                                                         
  '/usr/local/bin/node' '/usr/bin/uglifycss' '/tmp/inputtyeA2H'                                                                                            

  Error Output:                                                                                                                                            

  node.js:201                                                                                                                                              
          throw e; // process.nextTick error, or 'error' event on first tick                                                                               
                ^                                                                                                                                          
  Error: Cannot find module '/usr/bin/uglifycss'                                                                                                           
      at Function._resolveFilename (module.js:332:11)                                                                                                      
      at Function._load (module.js:279:25)                                                                                                                 
      at Array.0 (module.js:479:10)                                                                                                                        
      at EventEmitter._tickCallback (node.js:192:40)  

So obviously Assetic is looking for uglifycss in /usr/bin though I configured it to use a different path, /usr/local/bin. Does anyone know what's going on here?

like image 305
acme Avatar asked Jul 30 '13 09:07

acme


3 Answers

My Final configuration which appears to work is such:

  1. Set up config_prod

    app/config/config_prod.yml
    assetic:
        filters:
           uglifycss:
           bin: %kernel.root_dir%/Resources/node_modules/.bin/uglifyjs
           node: null
           apply_to: '*.css$'
    
  2. Dont put anything in config.yml about uglify. Leaves these in the config_(env).yml files

  3. Rebuild the cache

    app/console cache:clear --env=prod --no-debug
    
  4. Dump Assets

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

How i figured this out:

I had this problem and managed to fix it. I think my setup might have been ever so slightly different, in I had my uglify configuration split across app/config.yml and app/config_prod.yml

My configuration was identical to: http://symfony.com/doc/current/cookbook/assetic/uglifyjs.html :

app/config/config.yml
assetic:
 filters:
     uglifycss:
         bin: %kernel.root_dir%/Resources/node_modules/.bin/uglifyjs

app/config/config_prod.yml
assetic:
 filters:
     uglifycss:
         apply_to: "*.css$"

What i found was, Symfony was ignoring my variables in config.yml when it built the cache. You can see what it finds by looking in app/cache/prod/appProdProjectContainer.php and searching for 'uglifycss'. Mine looked like this:

protected function getAssetic_Filter_UglifycssService()
{
    $this->services['assetic.filter.uglifycss'] = $instance = new \Assetic\Filter\UglifyCssFilter('/usr/bin/uglifycss', '/usr/bin/node');

When i moved my bin: variable to config_prod.yml and rebuild the cache "cache:clear", it found the setting and pulled it in. However, node was still being passed as '/usr/bin/node'. Looking at the source for the Uglify Filter, it will use JUST the uglify path if the node variable is null. So, to use the binary of uglifycss, simply set node to null.

like image 169
Fodagus Avatar answered Nov 15 '22 20:11

Fodagus


If you have installed the binary of uglifycss, there is no need for specifying the path to node.

I'm pretty sure

assetic:
    filters:
        uglifycss:
            bin: /usr/local/bin/uglifycss
            apply_to: "\.css$"

should do the trick.

like image 1
Flask Avatar answered Nov 15 '22 21:11

Flask


Just make a symlink =)

ln -s /usr/local/bin/uglifycss /usr/bin/uglifycss

Not so dirty and works 100% =)

like image 1
Vasil Kulakov Avatar answered Nov 15 '22 21:11

Vasil Kulakov