make less-rails 添加行号作为注释
Make less-rails add line numbers as comment
有什么方法可以配置 less-rails
使其在注释中显示原始来源的行号?是否可以启用源映射?
考虑以下示例:
file1.less
body {
background-color: black;
}
file2.less
body {
padding: 20px;
}
application.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}
打开 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 sourcemaps:
MyProject::Application.configure do
config.less.source-map = true
config.less.source-map-map-inline = true
end
I really don't find the line config.less.line-numbers << "comments" in
docs
事实上,我的回答只是一个建议,我无法对其进行测试。以上建议您可以为 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.
and I am sure that it has a syntax error because of the dash between line
and numbers
我敢打赌你是对的。您应该尽可能使用:config.less.dumpLineNumbers
和 config.less.sourceMap
或在您的 config.less
中::dumpLineNumbers>comments
有什么方法可以配置 less-rails
使其在注释中显示原始来源的行号?是否可以启用源映射?
考虑以下示例:
file1.less
body {
background-color: black;
}
file2.less
body {
padding: 20px;
}
application.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}
打开 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 sourcemaps:
MyProject::Application.configure do
config.less.source-map = true
config.less.source-map-map-inline = true
end
I really don't find the line config.less.line-numbers << "comments" in docs
事实上,我的回答只是一个建议,我无法对其进行测试。以上建议您可以为 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.
and I am sure that it has a syntax error because of the dash between line and numbers
我敢打赌你是对的。您应该尽可能使用:config.less.dumpLineNumbers
和 config.less.sourceMap
或在您的 config.less
中::dumpLineNumbers>comments