RickStrahl / Westwind.AspnetCore.LiveReload

ASP.NET Core Live Reload Middleware that monitors file changes in your project and automatically reloads the browser's active page
Other
469 stars 42 forks source link

Add function to exclude specific files #32

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi, first of all I want to thank you for the effort.

I'd like to see an option to filter specific files from being watched.

I use webpack to generate some Razor partials (.cshtml) on each build (using the html-webpack-plugin). These partials are saved in ./Views/Shared/_generated_[chunk].cshtml. The content of this file does not change often (if at all), however it's regenerated on each change of the TypeScript/CSS files (built by Webpack using HMR), which will cause the LiveReload middleware to kick in.

I've tried to adjust the FolderToMonitor and ClientFileExtensions options, but without luck since ASP.NET Core only recognizes .cshtml as valid extension for partials. So there's no way for me to not conflict with the regular .cshtml (pages, layout files, etc.) files.

A possible proposal might be a lambda might be used the following way:

services.AddLiveReload(cfg =>
{
    cfg.IncludeFilter = (path) => {
        if (path.StartsWith("_generated") return false;
        return true;
    }
});

This also might be a possible solution for #22.

RickStrahl commented 4 years ago

Ouh - I like that approach!