少数多个文件导入(Less multiple files import)

我正在研究需要具有配色方案功能的WordPress主题。 我被迫少用这个项目。 我有一个名为schemes.less的文件,其中包含用于在网页上设置不同颜色部分样式的代码。 然后我设置了一些较少的文件:dark.less,light.less,blue.less等。我使用默认值技术导入它们( http://lesscss.org/features/#variables-feature-default-variables ) ,但是由于延迟加载,如果我每次都有相同的变量导入scheme.less多次。

有没有办法解决这个问题?

I'm working on WordPress theme that needs to have color schemes functionality. I am forced to use less on this project. I have file called schemes.less, that contains code for styling different colored sections on a webpage. Then I have set of less files called: dark.less, light.less, blue.less etc. I am importing them using default values technique (http://lesscss.org/features/#variables-feature-default-variables), but because of lazy loading if I import the scheme.less multiple times every time I have the same variables.

Are there any ways to workaround that?

最满意答案

使用“未命名”命名空间将主题彼此隔离:

& { @import (multiple) "schemes.less" @import "dark.less"; } & { @import (multiple) "schemes.less" @import "light.less"; } // etc.

(假设您使用的是最新的Less编译器,而不是lessphp - 对于那个,您需要进行少量修改 - 例如删除(multiple)等)。

Isolate themes from each other with "unnamed" namespaces:

& { @import (multiple) "schemes.less" @import "dark.less"; } & { @import (multiple) "schemes.less" @import "light.less"; } // etc.

(Assuming you're using an up-to-date Less compiler, not lessphp - for that one you need minor modifications - e.g. remove (multiple) etc.).

更多推荐