-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Pay What You Want for the Programming Into the Future Bundle
By News Staff,
- neowin deals
- pay what you want
- (and 15 more)
- 0 replies
- 6 views
-
Bag the full Programming Into the Future Bundle
By News Staff,
- neowin deals
- pay what you want
- (and 15 more)
- 4 replies
- 5 views
-
Pay What You Want for a 20-Course Programming Bundle
By News Staff,
- neowin dewals
- pay what you want
- (and 17 more)
- 0 replies
- 6 views
-
Pay What You Want for this 20-Course Programming Bundle
By News Staff,
- neowin deals
- pay what you want
- (and 14 more)
- 0 replies
- 5 views
-
Pay What You Want for this Learn to Web Design Bundle
By News Staff,
- neowin deals
- sponsored
- (and 12 more)
- 0 replies
- 408 views
-
Question
Kalint
What a pain in the ass to figure out when many of the other guides are for older versions or use dead projects. I'm throwing this up in case anyone else wants to get LESS in MVC5.
What I'll be using:
Visual Studio 2013 Professional (Express versions probably work fine)
Web Essentials 2013 (A free extension, not required but nice to have)
Twitter Bootstrap (Just awesome)
So... LET THE FUN BEGIN
1. Start with a new project then go to nuget and let's download what we need. If you are unfamiliar with nuget, its an awesome package management service.
Go to Tools > Library Package Manager > Manage NuGet Packages for solution...
2. Since Visual Studio 2013's release, there are already updates you can run on your project.
Click Updates and for the purpose of this guide, update:
> jQuery
> Microsoft ASP.NET Web Optimization Framework
> ANTLRv3
After this is done Click Online on the left side then in the search box type "Bootstrap Less Source". The current version is 3.0.2.
You'll see in the dependencies that LESS will also be installed. Install it.
Next, search for Bundle Transformer: LESS, Install this.
Finally, we need a javascript engine. Bundle Transformer will give you a head up about this and give you two options. Either MSIE or V8. I'll be installing V8 because it sounds cool.
Search for V8 and the first one should be "JavaScript Engine Switcher for .Net: V8", install it.
3. Associate V8 with Bundle Transformer (BT).
BT needs to know which engine to use so it can compile your LESS files. So in your solution, scroll to the bottom and open "Web.Config". If your config file looks like hell, Visual Studio has the best button of any IDE. Click Edit > Advanced > Format Document. SURPRISE! VS retabbed the structured XML!
To associate add the <less> block:
Save it.
4. Creating your bundles
Bundles are the new Jesus of the internet. They simply make life easier. For certain types like .js, MVC allows wildcards which is awesome.
Go to App_Start > BundleConfig.cs
First we need to type in our using statements so the file knows which libraries to use.
In the BT documentation there is another way to build your bundles but for the purpose of this, I'll be doing it the long way.
Now everything inside the scope of RegisterBundles, delete (This is entirely optional.)
Now within the same scope, create new instances of variables.
Next, associating our scripts
jQuery should always go first. Next Styles. What's nice about this is at compile time it automatically minifies the CSS.
Finally, we tell the bundles to optimize.
Ok so let's run our project quick!
OH GOD WHAT HAPPENED?!!! ohhh the humanity! The styles are dead!! ohhhhhh!!!!!!!!!
Hang on! On to step 5!
5. Associate our bundles with the layout
Go to Views > Shared > _Layout.cshtml
In the header add:
and down on the bottom of the body add:
Compile the project again and whaddya know LESS WORKS! Now you can configure your variables using LESS and save time!
KNOWN ISSUES:
Google is not happy with query strings.
2 Bad requests atm, tomorrow may have update.
Modernizr is not production version, get that at their website.
FINALLY:
If anyone knows some better solutions or fixes. DO TELL!
Link to comment
https://www.neowin.net/forum/topic/1191221-guide-to-getting-less-working-with-twitter-bootstrap-in-mvc-5/Share on other sites
7 answers to this question
Recommended Posts