-
Notifications
You must be signed in to change notification settings - Fork 15
How to use with Hot Reload? #31
Comments
This would be great feature for Blazor |
Hi there - yes the You shouldn't have to use (or even install) the CLI tool for this purpose. |
@johan-v-r I do not know if I understood you correctly. I can run my app, edit sass/scss file and this wil be automatically converted to css ? I tried this with blazor server on .Net 5 and It was not working. |
If you run your app with |
@johan-v-r Hello, on my side with
|
Has someone managed to use |
Struggling to get this working as well. Just in case you're not aware @johan-v-r this is Hot Reload we're talking about (not auto-builds) - specifically .NET/Blazor Watch's handling of Browser resource hot reloads:
That is what happens if you change a single CSS file and is what is referred to as a hot-reload - the resource/content file is updated on the server and re-sent to the browser without any full project build occuring. On the otherhand, here is what happens if I do the same to a SCSS file:
It seems like your plugin enforces some strict <ItemGroup>
<None Include="**/*.scss" />
</ItemGroup> I don't know too much about MSBuild and its targets but is it possible to trigger this package's build without requiring a full watch/build on SCSS files? |
As far as I can tell when hot reload (dotnet watch without args) detects a file change the following happens:
All of this is more or less hardwired in dotnet-watch, adding sass as Add this to your main csproj: <ItemGroup>
<!-- exclude sass files from main dotnet watch -->
<SassFile Update="@(SassFile)" Watch="false" />
</ItemGroup>
<!-- expose sass source files to helper project -->
<Target Name="CollectSassItems" Outputs="@(SassFile)" /> Create a new proj file e.g. <Project DefaultTargets="SassBuild">
<PropertyGroup>
<CustomCollectWatchItems>$(CustomCollectWatchItems);SassCollectWatchItems</CustomCollectWatchItems>
<!-- this is needed or else the watch process fails with NRE -->
<TargetFramework>net6.0</TargetFramework>
<!-- Path to your project here with the sass files to compile -->
<SassProject>Path\To\YourProjectThatHasSassToBuild.csproj</SassProject>
</PropertyGroup>
<!-- collect sass files from main project -->
<Target Name="SassCollectWatchItems">
<MSBuild Projects="$(SassProject)" Targets="CollectSassItems" BuildInParallel="true">
<Output TaskParameter="TargetOutputs" ItemName="Watch" />
</MSBuild>
</Target>
<!-- invoke sass compilation in the main project -->
<Target Name="SassBuild">
<MSBuild Projects="$(SassProject)" Targets="LibSass_DetermineBuildNeeded;LibSass_BuildArgsFromFileList;LibSass_Build" BuildInParallel="true" />
</Target>
<Import Project="$(MSBuildExtensionsPath)\Microsoft.Common.targets"/>
</Project> then finally run
This will run the LibSass pipeline for every changed sass, then the main |
I tried @bachratyg's workaround, but To make <ItemGroup>
<!-- exclude sass files from main dotnet watch -->
<SassFile Update="@(SassFile)" Watch="false" />
</ItemGroup> but also add the same for <ItemGroup>
<!-- exclude sass files from main dotnet watch -->
<SassFile Update="@(SassFile)" Watch="false" />
<!-- tell main dotnet watch to really ignore scss files -->
<Content Update="@(SassFile)" Watch="false" />
</ItemGroup> InfoLibSassBuilder: 2.0.1 |
@warappa you may have scss under wwwroot that gets picked up as
|
@bachratyg You're right, excluding them is actually better 👍 |
My VS is picking changes in css files automatically, but build of sass files happen only on run, is there a way to force it to compile on save? |
Hello, and thanks for this wonderful tool.
Currently, I'm working with a lot of SCSS files, and after each edit I
ALT+TAB
out to my Terminal and enterlsb
. Then lsb transforms all my *.scss files into *.css. dotnet will pick up these file changes, and then the gui is refreshed with new and fancy styles.Is it possible to watch for changes in *.scss files and run lsb upon save (a change in scss-file)? It's getting tedious to run lsb upon each edit...
I'm using 6.0.0-rc.1.21452.15.
The text was updated successfully, but these errors were encountered: