Import LESS file only for one page

≡放荡痞女 提交于 2019-12-01 03:35:49

问题


I have main all.less file, where I'm including all other less files

e.g.

@import "scaffolding.less";
@import "type.less";
@import "code.less";
@import "grid.less";
@import "homepage.less";

So my question is.

Is it possible to get"homepage.less" only in homepage (importing it in all.less).

Please Note that I don't want to attach it directly in the html file.

Thanks


回答1:


On your homepage use:

<body class="homepage">

And then in your Less files:

.homepage {
  @import "homepage.less";
}

The above still compiles all your code in a single file. Your compiled CSS code will have a larger number of bytes, but you can cache the same file for all your pages.




回答2:


If your homepage is seperate html file, then you should include separate css file to it.

I would suggest you to rethink your design. Because it seems that your css code is not so reusable. Here is a very good and free book that will teach you the concepts.




回答3:


That does not seem to be possible directly as all the less will eventually be compiled to css before being given to a page. Probably you need to create a separate file with a name like all_homepage.less for that purpose?



来源:https://stackoverflow.com/questions/30207921/import-less-file-only-for-one-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!