Symfony和Assetic;的NodeJS' UglifyCSS给出了语法错误

时间:2017-05-24 15:10:40

标签: php node.js symfony assetic

我在Windows 10上安装了Symfony / Assetic,以及带有uglifycss 0.0.27的Node.js。我从命令行获得版本号没有问题。

以下是我在Symfony for Assetic中的配置;

assetic:
    debug:          '%kernel.debug%'
    use_controller: false
    filters:
        cssrewrite: ~
        uglifycss:
            bin: C:\Users\User\AppData\Roaming\npm\uglifycss

以下是我的Twig模板中为我的CSS文件设置的过滤器;

{% stylesheets 'bundles/app/css/*' filter='cssrewrite, uglifycss' output='css/compiled/main.css' %}
        <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}

当我运行php bin / console assetic:dump时,我收到以下错误

[Assetic\Exception\FilterException]
  An error occurred while running:
  "C:\Program Files\nodejs\\node.EXE" "C:\Users\User\AppData\Roaming\npm\uglifycss" "C:\Users\User\AppData\Local\Temp
  \ass6151.tmp"
  Error Output:
  C:\Users\User\AppData\Roaming\npm\uglifycss:2
  basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
            ^^^^^^^
  SyntaxError: missing ) after argument list
      at createScript (vm.js:56:10)
      at Object.runInThisContext (vm.js:97:10)
      at Module._compile (module.js:542:28)
      at Object.Module._extensions..js (module.js:579:10)
      at Module.load (module.js:487:32)
      at tryModuleLoad (module.js:446:12)
      at Function.Module._load (module.js:438:3)
      at Module.runMain (module.js:604:10)
      at run (bootstrap_node.js:390:7)
      at startup (bootstrap_node.js:150:9)
  Input:
  .blue{
      background-color: orange;
  }

作为参考,这里是Assetic文件夹中设置的文件夹包含;

Node Files

1 个答案:

答案 0 :(得分:0)

实际上,uglifycss文件应该指向node_modules \ uglifycss \ uglifycss。但由于某种原因,这似乎不适用于Windows。所以我在配置中直接指向了它,现在它似乎正常工作。

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/node_modules/uglifycss/uglifycss" "$@"
  ret=$?
else 
  node  "$basedir/node_modules/uglifycss/uglifycss" "$@"
  ret=$?
fi
exit $ret