简体   繁体   English

Symfony2 uglify CSS和JS

[英]Symfony2 uglify CSS and JS

I am trying to 我在尝试着

php app/console assetic:dump PHP应用程序/控制台资产:转储

to test my prod environnement. 测试我的产品环境。 My css file is generating but not my js file. 我的css文件正在生成,而不是我的js文件。 I have this error message : 我有此错误消息:

C:\wamp\www\projet>php app/console assetic:dump --env=prod --no-debug
Dumping all prod assets.
Debug mode is off.

09:48:02 [file+] C:/wamp/www/projet/app/../web/css/666.css



[Assetic\Exception\FilterException]
An error occurred while running:
"C:\Program Files\nodejs\\node.EXE" "C:\wamp\www\projet\app\Resources\node_
modules\.bin\uglifycss" "C:\Users\GoeresAdmin\AppData\Local\Temp\inp3AC2.tm
p"

Error Output:

C:\wamp\www\projet\app\Resources\node_modules\.bin\uglifycss:4
case `uname` in
^^^^
SyntaxError: Unexpected token case
  at Module._compile (module.js:439:25)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Function.Module.runMain (module.js:497:10)
  at startup (node.js:119:16)
  at node.js:906:3

This is my javascript block in my layout : 这是我在布局中的javascript块:

{% block javascripts %}
  {# jQuery depuis le CDN de Google, ou fallback sur une copie locale #}
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
    {# Tous nos javascripts avec Assetic #}
  {% javascripts output='js/666.js' filter='?uglifyjs2' 
    'js/*.js' %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
  {% endjavascripts %}
{% endblock %}

And my running css block : 而我正在运行的css块:

{% block stylesheets %}
  {% stylesheets output='css/666.css' filter='?uglifycss'
    'css/*.css' %}
    <link rel="stylesheet" href="{{asset_url}}" type="text/css" />
  {% endstylesheets %}
{% endblock %}

I have this line in my app.php : 我的app.php中有这行:

$kernel = new AppKernel('prod', false);

My config.yml : 我的config.yml:

# Assetic Configuration
assetic:
debug:          %kernel.debug%
use_controller: false
bundles:        [ ]
filters:
    uglifyjs2:
        bin: %kernel.root_dir%/Resources/node_modules/.bin/uglifyjs
    uglifycss:
        bin: %kernel.root_dir%/Resources/node_modules/.bin/uglifycss

EDIT : 编辑:

I edited my code to use uglify instead of YUI. 我将代码编辑为使用uglify而不是YUI。 But it is worse than before because none of JS and CSS are running now in prod. 但这比以前更糟,因为现在产品中都没有运行JS和CSS。

You configured the wrong paths for the uglifyjs and uglifycss scripts. 您为uglifyjsuglifycss脚本配置了错误的路径。 Assetic executes these scripts via the executable of Node.js - but you configured the paths to the binary versions of uglifyjs and uglifycss instead (which are standalone). Assetic通过Node.js的可执行文件执行这些脚本-但是您配置了uglifyjsuglifycss二进制版本(独立的)的路径。

The correct configuration would be: 正确的配置为:

# Assetic Configuration
assetic:
debug:          %kernel.debug%
use_controller: false
bundles:        [ ]
filters:
    uglifyjs2:
        bin: %kernel.root_dir%/Resources/node_modules/uglify-js/bin/uglifyjs
    uglifycss:
        bin: %kernel.root_dir%/Resources/node_modules/uglifycss/uglifycss

The correct path to the uglifyjs script depends on your installed version. uglifyjs脚本的正确路径取决于您安装的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM