css - 为什么 grunt-contrib-less 找不到 Bootstrap 变量?

标签 css twitter-bootstrap less gruntjs

我正在编写一个网络应用程序,并希望将一些 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.  

我已经尝试了所有我能想到的方法,

最佳答案

这是因为您正在尝试编译 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'
    }
  }
}

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

关于css - 为什么 grunt-contrib-less 找不到 Bootstrap 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21672586/

相关文章:

css - 在 CSS @import 指令中包含 LESS 变量

html - 具有固定百分比的表格单元格不适用于许多元素

jquery - HTML 可扩展导航菜单

javascript - Firefox 字体失败

html - 使用 Rails 4 应用程序的 100% 浏览器宽度图像

css - Bootstrap 列高度

javascript - 如何根据窗口宽度使用 JavaScript 更改图像元素类?

css - 以 Twitter Bootstrap 为中心的登录表单

css - 如何将以下 LESS 转换为 SCSS

variables - Less > 在常量上定义变量