private void CreateFileSystemWatchers(BlazorConfig config) { // Watch for the "build completed" signal in the dist dir var distFileWatcher = new FileSystemWatcher(config.DistPath); distFileWatcher.Deleted += (sender, eventArgs) => { if (eventArgs.Name.Equals(BlazorBuildCompletedSignalFile, StringComparison.Ordinal)) { RequestReload(0); } }; distFileWatcher.EnableRaisingEvents = true; _pinnedWatchers.Add(distFileWatcher); // If there's a WebRootPath, watch for any file modification there // WebRootPath is only used in dev builds, where we want to serve from wwwroot directly // without requiring the developer to rebuild after changing the static files there. // In production there's no need for it. if (!string.IsNullOrEmpty(config.WebRootPath)) { var webRootWatcher = new FileSystemWatcher(config.WebRootPath); webRootWatcher.Deleted += (sender, evtArgs) => RequestReload(WebRootUpdateDelayMilliseconds); webRootWatcher.Created += (sender, evtArgs) => RequestReload(WebRootUpdateDelayMilliseconds); webRootWatcher.Changed += (sender, evtArgs) => RequestReload(WebRootUpdateDelayMilliseconds); webRootWatcher.Renamed += (sender, evtArgs) => RequestReload(WebRootUpdateDelayMilliseconds); webRootWatcher.EnableRaisingEvents = true; _pinnedWatchers.Add(webRootWatcher); } }
public static void UseBlazorLiveReloading( this IApplicationBuilder applicationBuilder, BlazorConfig config) { if (!string.IsNullOrEmpty(config.ReloadUri)) { var context = new LiveReloadingContext(); context.Attach(applicationBuilder, config); } }
public void Attach(IApplicationBuilder applicationBuilder, BlazorConfig config) { CreateFileSystemWatchers(config); AddWebSocketsEndpoint(applicationBuilder, config.ReloadUri); }