将 CSS 导入 LESS

Importing CSS into LESS

LESS 中是否有一个选项可以导入 CSS 文件的内容而不是添加 @import 指令?

例子

//example.less
@import url("../Css/site.css");
@import url("components.less");

//example.css
@import url("site.css"); // I DON'T WANT THIS!
.component1 { ... }
.component2 { ... }

这可以用 LESS 完成吗?

回答我自己的问题;是的!

@import (less) url("../Css/site.css");

在 less 中,您有不同的导入选项。

Syntax: @import (keyword) "filename";

The following import directives have been implemented:

  • reference: use a Less file but do not output it
  • inline: include the source file in the output but do not process it
  • less: treat the file as a Less file, no matter what the file extension
  • css: treat the file as a CSS file, no matter what the file extension
  • once: only include the file once (this is default behavior)
  • multiple: include the file multiple times
  • optional: continue compiling when file is not found

More than one keyword per @import is allowed, you will have to use commas to seperate the keywords: Example: @import (optional, reference) "foo.less";

更多信息在 docs