【问题标题】:Why does grunt-contrib-less not find bootstrap variables?为什么 grunt-contrib-less 找不到引导变量?
【发布时间】:2014-03-07 12:16:36
【问题描述】:

我正在编写一个网络应用程序,并希望将一些 css @media 查询连接到 Bootstrap 中的变量。所以我下载了 bootstrap 并决定让我的 grunt 编译它,当它编译我自己的 less 文件时。

我的 Gruntfile 的相关部分如下所示

less: { 
  dev: {
    options:{  
      paths: ['app/stylesheets', 'app/stylesheets/bootstrap'], // All the `less` files from bootstrap are placed in 'app/stylesheets/bootstrap' //  
    },  
    files: {  
      'build/pretty/style.css':'app/stylesheets/**/*.less'  
    }  
  }
}

但是当我运行 grunt grunt less:dev 它失败并输出

Running "less:dev" (less) task
>> NameError: variable @alert-padding is undefined in app/stylesheets/bootstrap/alerts.less on line 10, column 12:  
>> 9 .alert {  
>> 10   padding: @alert-padding;  
>> 11   margin-bottom: @line-height-computed;  
Warning: Error compiling app/stylesheets/bootstrap/alerts.less Use --force to continue.  

Aborted due to warnings.  

我想尽了办法,

【问题讨论】:

    标签: css twitter-bootstrap less gruntjs


    【解决方案1】:

    这是因为您尝试编译 app/stylesheets 目录中的每个 .less 文件,然后将它们连接到 build/pretty/style.css。这就是任务的工作方式。

    这样的事情你可能会有更好的运气:

    // app/stylesheets/style.less
    @import "bootstrap/bootstrap.less";
    
    // Now you'll have every bootstrap mixin, variable, class, etc available
    

    那么,在你的任务中:

    less: {
      dev: {
        files: {
          'build/pretty/style.css': 'app/stylesheets/style.less'
        }
      }
    }
    

    如果您只需要变量和 mixins,您可以使用 @import (reference) "bootstrap/bootstrap.less"; 代替。这样就不会输出任何 Bootstrap 样式。

    【讨论】:

    • 感谢 gustavohenke,但现在我收到此错误:正在运行“less:dev”(更少)任务 >> ParseError: Unrecognized input in app/stylesheets/style.less on line 7, column 1: > > 6 */ >> 7 @import "bootstrap/bootstrap.less"
    • @MartinJosefsson 我不明白,你能把你的 .less 文件贴在某个地方吗?
    • 我遇到了与@import 指令相同的“无法识别的输入”问题。我知道它是有效的 LESS,但我不明白为什么会出错。
    • 确保在导入的末尾添加分号!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 2014-01-23
    • 2014-03-21
    相关资源
    最近更新 更多