Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile Sass Files in .NET Core

I am trying to add Sass files to my .NET Core application in Visual Studio 2017. However, I cannot find any way to compile .scss files once I've made them. I sifted through NPM and Bower, but neither offer support for Sass.

The Microsoft documentation for adding Sass (https://docs.microsoft.com/en-us/aspnet/core/client-side/less-sass-fa) is outdated, and assumes that the project has a package.json file. Any guidance on enabling Sass compiling for my project would be much appreciated.

like image 861
kstuckey Avatar asked Sep 15 '17 20:09

kstuckey


People also ask

How does Sass get compiled?

Sass works by writing your styles in . scss (or . sass) files, which will then get compiled into a regular CSS file. The newly compiled CSS file is what gets loaded to your browser to style your web application.


2 Answers

The easiest way to add .scss to your ASP.NET Core apps is by going to the Nuget Package Manager and installing LigerShark.WebOptimizer.Core and LigerShark.WebOptimizer.Sass

After that, you can just put

<link rel="stylesheet" href="~/css/site.scss" />

in the head of the _Layout.cshtml file and the LigerShark.WebOptimizer.Sass package will compile all of your sass files automatically.

like image 199
smulholland2 Avatar answered Sep 21 '22 23:09

smulholland2


Use this extension for Visual Studio https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebCompiler

This extension not only lets you manually compile SASS/SCSS files to CSS, but it also adds a compilerconfig.json which can recompile your CSS every single time you click save.

Additionally, this extension can compile on project build via a nuget package it can install into your project. Which also enables CI/CD support.

This is by far the easiest way to add SCSS/SASS compilation to an ASP.NET Core Project when working inside of Visual Studio.

like image 23
Victorio Berra Avatar answered Sep 19 '22 23:09

Victorio Berra