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?
My Final configuration which appears to work is such:
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$'
Dont put anything in config.yml about uglify. Leaves these in the config_(env).yml files
Rebuild the cache
app/console cache:clear --env=prod --no-debug
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.
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.
Just make a symlink =)
ln -s /usr/local/bin/uglifycss /usr/bin/uglifycss
Not so dirty and works 100% =)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With