Serving dynamic variables to a less file at runtime

风流意气都作罢 提交于 2019-12-11 07:31:52

问题


We have a large ASP.NET MVC application with a large amount of CSS, ~105 distinct files. These files are separated by component, which makes them easier to manage. At runtime, we minify/combine these using a handler.

Additionally, our application utilizes skin settings; the administrator can customize fonts and colors for the site. Those skin settings are injected into CSS files using NVelocity, which although it's old is quite performant.

I'd like to move the CSS to using less, which will allow for more code reuse and cleanliness inside the CSS files. I'm struggling over the best option to do this. My current train of thought is this:

  1. Administrator makes skin modifications, and saves
  2. On save the application generates a skin.less file on disc, which is the master less file containing all the variables
  3. Subsequent CSS files that require less variables do an @import on the skin.less
  4. less files are processed and minified/combined in a handler, and served down to the client.

My question is, does this seem like the best approach to serving dynamic variables into the less files? Is generating the skin.less file on disc my only option, or can the @import statement reference a handler itself, so there's no need to generate a file on disc?


回答1:


I think you can possibly do it this way. Not quite the same thing you are talking about, but I did a bit of a proof of concept for using LESS with skinning here:

https://github.com/aguyawry/less_tests

I think one difference is that in this POC, the branded less file is the one loaded in the markup and it imports the base app styles, then specifies new vars that override the initial values in the base.

This POC is all client side, but in practice we do this server side as well. We are actually moving toward building a UI for clients to choose their styles themselves (bg color, border color....) and then will render out a skin style sheet from that into the system.

I don't think the comment by TheZ applies since you are doing everything server side. Blocking would only happen if you were doing this client side.



来源:https://stackoverflow.com/questions/12730896/serving-dynamic-variables-to-a-less-file-at-runtime

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