Skip to content

Instantly share code, notes, and snippets.

@Joren-Thijs
Created June 18, 2021 20:43
Show Gist options
  • Save Joren-Thijs/d1e1431d30bc70fbd99f004ab6654f27 to your computer and use it in GitHub Desktop.
Save Joren-Thijs/d1e1431d30bc70fbd99f004ab6654f27 to your computer and use it in GitHub Desktop.
Csproj file with support for compiling scss files with dotnet watch.
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net5</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
</ItemGroup>
<!-- Add SCSS files to dotnet watch -->
<ItemGroup>
<Watch Include="**\*.scss" />
<None Update="**\*.css" watch="false" />
</ItemGroup>
<!-- Compile SCSS files into CSS -->
<ItemGroup>
<ComponentScssFiles Include="**/*/*.scss" Exclude="node_modules/**;wwwroot/**;Styles/**" />
</ItemGroup>
<Target Name="CompileComponentSass" BeforeTargets="CompileGlobalSass">
<Message Text="Compiling Component SCSS files" Importance="high" />
<Exec Condition="!$([System.Text.RegularExpressions.Regex]::IsMatch('%(ComponentScssFiles.Identity)', `.*[/\\]_.*`))" Command="npm run sass -- --style=compressed --no-source-map --load-path=Styles/Core %(ComponentScssFiles.Identity) %(relativedir)%(filename).css" />
</Target>
<Target Name="CompileGlobalSass" BeforeTargets="Compile">
<Message Text="Compiling global SCSS file" Importance="high" />
<Exec Command="npm run sass -- --style=compressed Styles:wwwroot/css" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment