From 2c268a4eca153ea2a3dcd3698e08092c82eb9bd7 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Thu, 1 Mar 2018 10:32:58 +0000 Subject: [PATCH] Live reloading (currently enabled only for command-line builds - will add VS support next) --- Blazor.sln | 12 ++ .../src/Boot.ts | 8 + .../src/LiveReloading.ts | 48 ++++++ .../Cli/Commands/BuildIndexHtmlCommand.cs | 5 + .../Core/IndexHtmlWriter.cs | 23 ++- .../targets/All.props | 9 ++ .../targets/All.targets | 3 +- .../targets/Blazor.MonoRuntime.props | 6 +- .../targets/Blazor.MonoRuntime.targets | 23 ++- .../BlazorAppBuilderExtensions.cs | 15 +- .../BlazorConfig.cs | 18 +++ .../LiveReloadingContext.cs | 140 ++++++++++++++++++ .../LiveReloadingExtensions.cs | 21 +++ .../Microsoft.AspNetCore.Blazor.Server.csproj | 1 + .../IndexHtmlWriterTest.cs | 30 +++- .../ServerFixtures/DevHostServerFixture.cs | 19 ++- ...Microsoft.AspNetCore.Blazor.E2ETest.csproj | 1 + .../Tests/LiveReloadingTest.cs | 118 +++++++++++++++ test/testapps/LiveReloadTestApp/Home.cshtml | 1 + .../LiveReloadTestApp.csproj | 21 +++ test/testapps/LiveReloadTestApp/Program.cs | 15 ++ .../LiveReloadTestApp/wwwroot/index.html | 19 +++ .../LiveReloadTestApp/wwwroot/someJsFile.js | 3 + 23 files changed, 539 insertions(+), 20 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Blazor.Browser.JS/src/LiveReloading.ts create mode 100644 src/Microsoft.AspNetCore.Blazor.Server/LiveReloadingContext.cs create mode 100644 src/Microsoft.AspNetCore.Blazor.Server/LiveReloadingExtensions.cs create mode 100644 test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/LiveReloadingTest.cs create mode 100644 test/testapps/LiveReloadTestApp/Home.cshtml create mode 100644 test/testapps/LiveReloadTestApp/LiveReloadTestApp.csproj create mode 100644 test/testapps/LiveReloadTestApp/Program.cs create mode 100644 test/testapps/LiveReloadTestApp/wwwroot/index.html create mode 100644 test/testapps/LiveReloadTestApp/wwwroot/someJsFile.js diff --git a/Blazor.sln b/Blazor.sln index 909b4b5165..853eabe2ae 100644 --- a/Blazor.sln +++ b/Blazor.sln @@ -90,6 +90,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.VisualStudio.Blaz EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestContentPackage", "test\testapps\TestContentPackage\TestContentPackage.csproj", "{C57382BC-EE93-49D5-BC40-5C98AF8AA048}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiveReloadTestApp", "test\testapps\LiveReloadTestApp\LiveReloadTestApp.csproj", "{0246AA77-1A27-4A67-874B-6EF6F99E414E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -281,6 +283,7 @@ Global {F3E02B21-1127-431A-B832-0E53CB72097B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F3E02B21-1127-431A-B832-0E53CB72097B}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU {F3E02B21-1127-431A-B832-0E53CB72097B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3E02B21-1127-431A-B832-0E53CB72097B}.Release|Any CPU.Build.0 = Release|Any CPU {F3E02B21-1127-431A-B832-0E53CB72097B}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU {FF25111E-5A3E-48A3-96D8-08A2C5A2A91C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FF25111E-5A3E-48A3-96D8-08A2C5A2A91C}.Debug|Any CPU.Build.0 = Debug|Any CPU @@ -312,6 +315,14 @@ Global {C57382BC-EE93-49D5-BC40-5C98AF8AA048}.Release|Any CPU.Build.0 = Release|Any CPU {C57382BC-EE93-49D5-BC40-5C98AF8AA048}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU {C57382BC-EE93-49D5-BC40-5C98AF8AA048}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {0246AA77-1A27-4A67-874B-6EF6F99E414E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0246AA77-1A27-4A67-874B-6EF6F99E414E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0246AA77-1A27-4A67-874B-6EF6F99E414E}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {0246AA77-1A27-4A67-874B-6EF6F99E414E}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {0246AA77-1A27-4A67-874B-6EF6F99E414E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0246AA77-1A27-4A67-874B-6EF6F99E414E}.Release|Any CPU.Build.0 = Release|Any CPU + {0246AA77-1A27-4A67-874B-6EF6F99E414E}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {0246AA77-1A27-4A67-874B-6EF6F99E414E}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -352,6 +363,7 @@ Global {43E39257-7DC1-46BD-9BD9-2319A1313D07} = {F563ABB6-85FB-4CFC-B0D2-1D5130E8246D} {9088E4E4-B855-457F-AE9E-D86709A5E1F4} = {F563ABB6-85FB-4CFC-B0D2-1D5130E8246D} {C57382BC-EE93-49D5-BC40-5C98AF8AA048} = {4AE0D35B-D97A-44D0-8392-C9240377DCCE} + {0246AA77-1A27-4A67-874B-6EF6F99E414E} = {4AE0D35B-D97A-44D0-8392-C9240377DCCE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {504DA352-6788-4DC0-8705-82167E72A4D3} diff --git a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts index 065c711523..7ddd84ff61 100644 --- a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts +++ b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Boot.ts @@ -1,5 +1,6 @@ import { platform } from './Environment'; import { getAssemblyNameFromUrl } from './Platform/DotNet'; +import { enableLiveReloading } from './LiveReloading'; import './Rendering/Renderer'; import './Services/Http'; import './Services/UriHelper'; @@ -36,6 +37,13 @@ async function boot() { // Start up the application platform.callEntryPoint(entryPointAssemblyName, entryPointMethod, []); + + // Enable live reloading only if there's a "reload" attribute on the + + + + diff --git a/test/testapps/LiveReloadTestApp/wwwroot/someJsFile.js b/test/testapps/LiveReloadTestApp/wwwroot/someJsFile.js new file mode 100644 index 0000000000..af61769b29 --- /dev/null +++ b/test/testapps/LiveReloadTestApp/wwwroot/someJsFile.js @@ -0,0 +1,3 @@ +// We modify this on disk during E2E tests to verify it causes a reload +var valueToWrite = 'initial value'; +document.getElementById('some-js-file-output').textContent = valueToWrite;