dongyue9864 2014-07-09 14:35
浏览 60
已采纳

使用Symfony 2.5和UglifyCSS / JS缩小/聚合CSS / JS文件的问题

I have followed these instructions in order to enable both UglifyJs2 and UglifyCss on my development environment (to start with... can't risk taking down the production server with this problem!)

Under my config_dev.yml I have configured the following (I've started with just the bin parameters but added extra configurations just in case something else was causing a problem.)

assetic:
    use_controller: %use_assetic_controller%
    filters:
        uglifycss:
            bin: "%kernel.root_dir%/Resources/node_modules/.bin/uglifycss"
            node: /usr/local/bin/node
            apply_to: '\.css$'
        uglifyjs2:
            bin: "%kernel.root_dir%/Resources/node_modules/.bin/uglifyjs"
            node: /usr/local/bin/node
            apply_to: '\.js$'

and in my base.html.twig file:

  {% javascripts  'bundles/fosjsrouting/js/router.js'
                  'bundles/legalcheck/js/angular.min.js'
                  'bundles/legalcheck/js/plugins/*'
                  'bundles/legalcheck/js/app.js'
                  'bundles/legalcheck/js/controllers/*'
                  filter='uglifyjs2'
                %}
      <script type="text/javascript" src="{{ asset_url }}"></script>
  {% endjavascripts %}

and

  {% stylesheets 'bundles/legalcheck/css/*' filter='cssrewrite' filter='uglifycss' %}
  <link rel="stylesheet" href="{{ asset_url }}" />
  {% endstylesheets %}

When I run php app/console assetic:dump --env=prod --verbose, all files are generated with no errors. They're even minified at this point!

However, when I load the app in the browser, all of the CSS and JS assets return a 500 error.

500 Errors

Here's what each Javascript file returns, along with what each CSS file returns. I am getting a signal "5" error from what seems like both UglifyJS and/or UglifyCSS, or Node itself. I suspect the wrong thing is being sent somewhere.

Any ideas? I'm running a local MAMP server to achieve a development environment. Also note I've taken the space out of "Git Repos" in my path to avoid obvious problems like path issues as a troubleshooting step.

Update

I tried running the same settings in config_dev.yml into my config_prod.yml and found that everything works perfectly on the production side. It seems that trying to load the minified assets through app_dev.php causes problems... but I still don't know what! It would be nice if minification could be tested through the dev environment, which is why I'm leaving the question open for both this problem and to encourage dialogue for a solution.

  • 写回答

1条回答 默认 最新

  • dongzai0020 2014-07-09 23:13
    关注

    assetic's debug mode :)

    you're dumping the files with --prod ( which has debug mode disabled by default) ...

    ... and try to access them in the dev environment afterwards.

    If debug mode is enabled asset collections will be split into multiple files that look like this:

    <hash>_partX_<filename>.js
    

    This is what chrome devtools shows you and a problem while dumping on-the-fly leads to the 500 errors.

    You didn't dump these files for debugging with the command you invoked and (as long as you don't have use_controller: true) they won't be dumped on the fly either.

    If you have use_controller: true ... any non-zero exit code of a filter-run will result in a 500 error. That's what you experience.


    solution:

    Either disable debug mode for a single asset collection like this ...

    {% javascripts  '...'
        filter='uglifyjs2'
        debug=false
     %}
    

    ... or add ...

    assetic:
      debug: false
    

    to your config_dev.yml to resolve the issue.

    Finally dump your assets with app/console assetic:dump and the correct environment flag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能