How can I apply less stylesheets as a css on the fly?
Recently I started to experiment with LESS, and Im really enthusiastic about it. Its a really nice tool to optimize css. Anyway I installed into my project file as it was written on their website 4 steps, very EZ. I use MVC3 framework with razor engine, and in my view I just can not apply the .less files as a css for the browser.
When I used like this, its just worked brilliantly
<style type="text/css">
@Less.Parse(".transparency(@opacity: 50) {opacity:@opacity/100; filter:~'alpha(opacity = '@opacity~')';}.disabled {.transparency}")
</style>
But when I tried to apply it as a css file the browser just ignored it
<link rel="stylesheet/less" type="text/css" href="/Content/Css/Pm/Pm.less" media="screen" />
I had no comp开发者_如何学编程iling error in my less file, and the compiled less just looked great, I thought dotless going to handle it automatically, but apparently thats not the case. Im not sure what would be the best approach, read out the less file content as a stream and write it back into a css file or modify the view engine like int this article or write a helper like this?
If you are concerned about CPU usage, you could always look at using precompilation, take a look at this question: Visual studio - precompile - dotless
The answers give a number of options:
- Pre-build task in your project file
- Chirpy
- Command-line using the dotless compiler
- A number of people also wrote custom build tools (including myself): JsBuildTools, LessCssForVisualStudio
精彩评论