Assetic dump does not find uglifycss in my Symfony app
Asked Answered
T

3

5

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?

Taproot answered 30/7, 2013 at 9:30 Comment(5)
Did you ever solve this? I have the same problem. I can fix it by symlinking the executable to /usr/bin/uglifyjs, but i wanted something local in my app/Resources directory so I could deploy it with version control.Woodsia
No, haven't found a solution so far. Though I have to admit I haven't tried it in the last weeks. Maybe it's an Assetic bug that has been fixed.Taproot
This is annoying me, so I'm debugging/diving the source. So far i found this in the app/cache/Prod/appProdProjectContainer.php: $this->services['assetic.filter.uglifyjs2'] = $instance = new \Assetic\Filter\UglifyJs2Filter('/usr/bin/uglifyjs', '/usr/bin/node'); The filter is NOT being passed the values we set in the .yml file, so when the service is generated it's not finding the keys. Still looking...Woodsia
So it looks like the just forgot to pass the configuration to the service instance?Taproot
It seems more like it only reads the node and bin paths out of the environment-specific config files. Or only passes them if they're in the environment specific files. Or the env specific configurations completely override the settings from the main config file (instead of merging them). I'm not sure which.Woodsia
W
8

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.

Woodsia answered 11/10, 2013 at 21:20 Comment(1)
Note: you can have configuration in both files, it's just that Symfony will not merge the configuration and environment specific configuration will overwrite your previous configuration.Derivative
A
1

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.

Artful answered 30/7, 2013 at 12:7 Comment(1)
I already tried that one before, it does not work, too. The path is simply ignored. It's just as if it doesn't use this config file at all, though I double- and tribble-checked everything.Taproot
P
1

Just make a symlink =)

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

Not so dirty and works 100% =)

Plowshare answered 1/8, 2014 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.