1

有什么方法可以配置less-rails,以便将原始来源的行号显示为注释?是否可以启用源映射?

考虑以下示例:

文件1.less

body {
  background-color: black;
}

文件2.less

body {
  padding: 20px;
}

应用程序.css.less

@import "file1";
@import "file1";

我得到什么:

body {
  background-color: black;
}

body {
  padding: 20px;
}

我想要的是

/* file1.less line: 1 */
body {
  background-color: black;
}

/* file2.less line: 1 */
body {
  padding: 20px;
}

或者有没有其他更简单的方法来找出哪个规则属于哪个文件?

更新

配置我的应用程序时,config.less仅包含以下内容:

{:paths=>
  [#<Pathname:/home/yan-foto/.../vendor/less>,
   #<Pathname:/home/yan-foto/.../node_modules/bootstrap-datetimepicker>,
   #<Pathname:/home/yan-foto/.../node_modules/bootstrap-slider>],
 :compress=>false}
4

1 回答 1

1

打开vendor/bundle/ruby/1.9.1/gems/less-2.6.0/lib/less/parser.rb文件并替换(大约第 54 行):

  end
  @parser = Less::JavaScript.exec { Less['Parser'].new(env) }

和:

  end
  env['dumpLineNumbers'] = 'comments';
  @parser = Less::JavaScript.exec { Less['Parser'].new(env) }

基于https://github.com/metaskills/less-rails#configuration你应该尝试:

MyProject::Application.configure do
  config.less.line-numbers << "comments"
  config.less.compress = true
end

当前面的工作按预期工作时,您还可以考虑使用 CSS 源映射:

MyProject::Application.configure do
  config.less.source-map = true
  config.less.source-map-map-inline = true
end

我真的在文档中找不到 config.less.line-numbers << "comments" 这一行

我实际上我的回答只是一个建议,我无法测试它。以上建议您可以为 Less 编译器设置一些选项。

您还可以通过lessc不带任何参数运行来找到此选项:

-------------------------- Deprecated ----------------
  --line-numbers=TYPE      Outputs filename and line numbers.
                           TYPE can be either 'comments', which will output
                           the debug info within comments, 'mediaquery'
                           that will output the information within a fake
                           media query which is compatible with the SASS
                           format, and 'all' which will do both.
  --verbose                Be verbose.

我确信它有语法错误,因为行和数字之间的破折号

我敢打赌你是对的。你应该可以使用:config.less.dumpLineNumbersconfig.less.sourceMap

或在您的config.less:dumpLineNumbers>comments

于 2015-02-02T22:08:38.053 回答