css - SASS 没有在 symfony 中编译

标签 css symfony sass assetic

我正在尝试将 SASS 与带有 symfony 的 Assetic 捆绑包一起使用。我按照主教程 here .但是,它不会生成任何 css 文件。我尝试过使用不同的输出、检查文件权限和弄乱过滤器,但我不太确定从这里去哪里。

相关的 config.yml 代码:

# Assetic Configuration    
assetic:
    debug:          '%kernel.debug%'
    use_controller: '%kernel.debug%'
    filters:
        cssrewrite: ~
        scssphp: 
          bin: /usr/local/lib/ruby/gems/2.3.0/gems/sass-3.4.24
          apply_to: .scss$

这是我在 base.html.twig 中包含的 stylesheet.html.twig
{% stylesheets 
    'sass/style.scss' 
    filter = "scssphp" output='css/sass.css' %}
    <link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}

我尝试使用以下命令行:
php bin/console assetic:dump --env=prod --no-debug

并得到以下错误:
[Assetic\Exception\FilterException]                                          
  An error occurred while running:                                             
  '/usr/local/lib/ruby' '/usr/local/lib/ruby/gems/2.3.0/gems/sass-3.4.24' '--  
  load-path' '/Applications/XAMPP/xamppfiles/htdocs/my_website/app/../web/sas  
  s' '--scss' '--load-path' '/Applications/XAMPP/xamppfiles/htdocs/my_website  
  /app/../web' '--cache-location' '/Applications/XAMPP/xamppfiles/htdocs/my_w  
  ebsite/var/cache/prod' '/private/var/folders/_2/xkw80vl13zj0xw0nm7j8c4bc000  
  0gn/T/assetic_sassqn8iBF'                                                    
  Error Output:                                                                
  sh: /usr/local/lib/ruby: is a directory                                      
  sh: line 0: exec: /usr/local/lib/ruby: cannot execute: Undefined error: 0    
  Input:
  [...]

错误的其余部分只是我的 scss 文件。我不太确定错误告诉我什么。

谢谢 :)

最佳答案

我认为您需要找到 ruby 的正确路径(该错误意味着 /usr/local/lib/ruby 不是您的 ruby​​ 解释器,而只是一个文件夹)和 sass .

  • 执行which ruby .它将打印到 ruby​​ 的路径。对我来说是 /usr/bin/ruby .
  • 在您的配置中设置正确的路径:
  •     assetic:
            debug:          '%kernel.debug%'
            use_controller: '%kernel.debug%'
            ruby: /usr/bin/ruby
            filters:
                cssrewrite: ~
                scssphp: 
                bin: /usr/local/lib/ruby/gems/2.3.0/gems/sass-3.4.24        
                apply_to: .scss$
    
    1. If it still doesn't work, probably you need to find the correct path of sass too. I'm looking for it in this folders:

      find /usr/local/bin/ | grep sass find /usr/bin/ | grep sass find /usr/lib/ | grep sass

    The first command gave to me this output:

    /usr/local/bin/sass-convert
    /usr/local/bin/node-sass
    /usr/local/bin/sass
    

    最后一行显示了路径。尝试在您的配置中更改它,如下所示:
    assetic:
        debug:          '%kernel.debug%'
        use_controller: '%kernel.debug%'
        ruby: /usr/bin/ruby
        filters:
            cssrewrite: ~
            scssphp: 
              bin: /usr/local/bin/sass
              apply_to: .scss$
    

    让我知道它是否有效。

    关于css - SASS 没有在 symfony 中编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44447419/

    相关文章:

    php - 页脚不会停留下来

    php - Symfony2 和 Vim 推荐

    arrays - symfony twig渲染 Controller 参数数组

    html - 使用 CSS 的水平表格布局

    jquery - 消除滚动条并将嵌入式 pdf 放入我的 jquery 对话框中

    css - 单击时切换 CSS3 动画

    java - Symfony 执行访问数据库的 java 程序

    sass - polymer 1.1 和 SASS

    Angular-CLI Sass

    css - BEM命名与定位