Skip to content

Commit 16f4ada

Browse files
Merge pull request #9 from SQL-MisterMagoo/chucker-master
Chucker master - local branch for PR #5
2 parents 0757890 + c092c2b commit 16f4ada

7 files changed

+58
-10
lines changed

Blazor.PWA.MSBuild.Tasks/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>1.0.1</VersionPrefix>
3+
<VersionPrefix>1.0.2</VersionPrefix>
44
<VersionSuffix>beta$([System.DateTime]::Now.ToString("yyyyMMdd-HHmmss"))</VersionSuffix>
55
<VersionSuffix Condition="'$(Configuration)' == 'Release'"></VersionSuffix>
66
</PropertyGroup>

Blazor.PWA.MSBuild.Tasks/build/BlazorPWA.MSBuild.Manifest.targets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
<!-- Base URL for the app -->
1515
<ManifestBaseUrl Condition="'$(ManifestBaseUrl)' == ''">/</ManifestBaseUrl>
16+
<ManifestBaseUrl Condition="!'$(ManifestBaseUrl.StartsWith(/))'">/$(ManifestBaseUrl)</ManifestBaseUrl>
17+
<ManifestBaseUrl Condition="!'$(ManifestBaseUrl.EndsWith(/))'">$(ManifestBaseUrl)/</ManifestBaseUrl>
1618

1719
<!-- Please see https://developers.google.com/web/fundamentals/web-app-manifest/#display for options -->
1820
<ManifestDisplay Condition="'$(ManifestDisplay)' == ''">standalone</ManifestDisplay>
@@ -82,7 +84,7 @@
8284
<WriteLinesToFile
8385
File="$(IndexFile)"
8486
Overwrite="true"
85-
Lines="$(IndexLines.Replace('&lt;/head&gt;',' &lt;link href=&quot;/$(ManifestFileName)&quot; rel=&quot;manifest&quot;/&gt;%0D%0A&lt;/head&gt;'))"
87+
Lines="$(IndexLines.Replace('&lt;/head&gt;',' &lt;link href=&quot;$(ManifestBaseUrl)$(ManifestFileName)&quot; rel=&quot;manifest&quot;/&gt;%0D%0A&lt;/head&gt;'))"
8688
Condition="'$(IndexLines.Contains(rel=&quot;manifest&quot;))'=='false'"/>
8789
</Target>
8890
</Project>

Blazor.PWA.MSBuild.Tasks/build/BlazorPWA.MSBuild.ServiceWorker.targets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
<!-- Setup the declarations for the Service Worker -->
5151
<ServiceWorkerConstants Condition="'$(ServiceWorkerConstants)' == '' AND '$(BlazorProjectType)' == 'CSB'">
52-
const baseURL = '$(ServiceWorkerBaseURL)'%3B;
52+
const baseURL = '$(ServiceWorkerBaseUrl)'%3B;
5353
const indexURL = '$(ServiceWorkerBaseUrl)$(ProjectIndexPage)'%3B;
5454
const networkFetchEvent = '$(ServiceWorkerNetworkFetchEvent)'%3B;
5555
const swInstallEvent = '$(ServiceWorkerInstallEvent)'%3B;
@@ -61,7 +61,7 @@
6161

6262
<!-- Setup the declarations for the Service Worker -->
6363
<ServiceWorkerConstants Condition="'$(ServiceWorkerConstants)' == '' AND '$(BlazorProjectType)' == 'SSB'">
64-
const baseURL = '$(ServiceWorkerBaseURL)'%3B;
64+
const baseURL = '$(ServiceWorkerBaseUrl)'%3B;
6565
const indexURL = '$(ServiceWorkerBaseUrl)$(ProjectHomePage)'%3B;
6666
const networkFetchEvent = '$(ServiceWorkerNetworkFetchEvent)'%3B;
6767
const swInstallEvent = '$(ServiceWorkerInstallEvent)'%3B;
@@ -105,7 +105,7 @@
105105
<WriteLinesToFile Condition="'$(BlazorProjectType)' == 'CSB'"
106106
File="$(WWWRoot)$(ServiceWorkerFileName)"
107107
Overwrite="false"
108-
Lines="const requiredFiles = [;@(DistFiles -> '&quot;/%(RecursiveDir)%(FileName)%(Extension)&quot;'->Replace('\','/'),',%0D%0A');]%3B;" />
108+
Lines="const requiredFiles = [;@(DistFiles -> '&quot;$(ServiceWorkerBaseUrl)%(RecursiveDir)%(FileName)%(Extension)&quot;'->Replace('\','/'),',%0D%0A');]%3B;" />
109109
<WriteLinesToFile Condition="'$(BlazorProjectType)' == 'CSB'"
110110
File="$(WWWRoot)$(ServiceWorkerFileName)"
111111
Overwrite="false"

Blazor.PWA.MSBuild.Tasks/build/BlazorPWA.MSBuild.ServiceWorkerRegister.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<ServiceWorkerBlazorInstallMethod Condition="'$(ServiceWorkerBlazorInstallMethod)'==''">PWAInstallable</ServiceWorkerBlazorInstallMethod>
3535
<!-- Setup the declarations for the Service Worker Register -->
3636
<ServiceWorkerRegisterConstants Condition="'$(ServiceWorkerRegisterConstants)' == ''">
37-
const serviceWorkerFileName = '$(ServiceWorkerBaseURL)$(ServiceWorkerFileName)'%3B;
37+
const serviceWorkerFileName = '$(ServiceWorkerBaseUrl)$(ServiceWorkerFileName)'%3B;
3838
const swInstalledEvent = '$(ServiceWorkerInstalledEvent)'%3B;
3939
const staticCachePrefix = '$(ServiceWorkerCacheName)-v'%3B;
4040
const updateAlertMessage = '$(ServiceWorkerUpdateAlertText)'%3B;
@@ -110,7 +110,7 @@
110110
<WriteLinesToFile
111111
File="$(IndexFile)"
112112
Overwrite="true"
113-
Lines="$(IndexLines.Replace('&lt;/head&gt;',' &lt;script src=&quot;$(ServiceWorkerRegisterFileName)&quot;&gt;&lt;/script&gt;%0D%0A&lt;/head&gt;'))"
113+
Lines="$(IndexLines.Replace('&lt;/head&gt;',' &lt;script src=&quot;$(ServiceWorkerBaseUrl)$(ServiceWorkerRegisterFileName)&quot;&gt;&lt;/script&gt;%0D%0A&lt;/head&gt;'))"
114114
Condition="'$(IndexLines.Contains($(ServiceWorkerRegisterFileName)))'=='false'"
115115
/>
116116

Blazor.PWA.MSBuild.Tasks/build/BlazorPWA.MSBuild.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
<!-- The "home route" url for the application -->
3030
<ServiceWorkerBaseUrl Condition="'$(ServiceWorkerBaseUrl)' == ''">/</ServiceWorkerBaseUrl>
31+
<ServiceWorkerBaseUrl Condition="!'$(ServiceWorkerBaseUrl.StartsWith(/))'">/$(ServiceWorkerBaseUrl)</ServiceWorkerBaseUrl>
32+
<ServiceWorkerBaseUrl Condition="!'$(ServiceWorkerBaseUrl.EndsWith(/))'">$(ServiceWorkerBaseUrl)/</ServiceWorkerBaseUrl>
3133

3234
<!-- The CSB home page served up for the base URL -->
3335
<ProjectIndexPage Condition="'$(ProjectIndexPage)' == ''">index.html</ProjectIndexPage>

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
#### 06/12/2019
2+
3+
- PR #5 from @chucker merged with these changes
4+
- Bug: **Property** **`ManifestBaseUrl`** - used to specify the base Url in the manifest.json was not being used in the index `<head>` link for **manifest.json**
5+
- Bug: **Property** **`ServiceWorkerBaseUrl`** - used to specify the base Url in the ServiceWorker was not being used in the _required files_ list.
6+
- Bug: **Property** **`ServiceWorkerBaseUrl`** - used to specify the base Url in the ServiceWorker was not being used in the index `<head>` link for **ServiceWorker.js**
7+
- Also @SQL-MisterMagoo
8+
- Added code to automatically add leading and trailing slashes to **Property** **`ManifestBaseUrl`**
9+
- Added code to automatically add leading and trailing slashes to **Property** **`ServiceWorkerBaseUrl`**
10+
111
#### 11/11/2019
212

313
- Added new **Property** **`ServiceWorkerIgnoreHosts`** - used to prevent service worker installation on specific hosts e.g. localhost

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ I don't have a Mac, but I believe Safari does not prompt on desktop either.
2121
Install the nuget BlazorPWA.MsBuild
2222

2323
#### Package Manager:
24-
`Install-Package BlazorPWA.MSBuild -Version 1.0.1`
24+
`Install-Package BlazorPWA.MSBuild -Version 1.0.2`
2525

2626
#### .NET Cli:
27-
`dotnet add package BlazorPWA.MSBuild --version 1.0.1`
27+
`dotnet add package BlazorPWA.MSBuild --version 1.0.2`
2828

2929
#### Package Reference
30-
`<PackageReference Include="BlazorPWA.MSBuild" Version="1.0.1"/>`
30+
`<PackageReference Include="BlazorPWA.MSBuild" Version="1.0.2"/>`
3131

3232
## Configuration
3333

@@ -171,6 +171,40 @@ The service worker will not register itself when the `hostname` matches anything
171171

172172
*Note: the single quotes around each hostname are required for now*
173173

174+
### Handle different base Urls for different configurations
175+
176+
Sample csproj file for two different base Urls
177+
178+
``` XML
179+
<Project Sdk="Microsoft.NET.Sdk.Web">
180+
181+
<PropertyGroup>
182+
<TargetFramework>netcoreapp3.1</TargetFramework>
183+
<ManifestForce>true</ManifestForce>
184+
<ServiceWorkerForce>true</ServiceWorkerForce>
185+
</PropertyGroup>
186+
187+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
188+
<ServiceWorkerBaseUrl>prod</ServiceWorkerBaseUrl>
189+
<ManifestBaseUrl>prod</ManifestBaseUrl>
190+
</PropertyGroup>
191+
192+
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
193+
<ServiceWorkerBaseUrl>dev</ServiceWorkerBaseUrl>
194+
<ManifestBaseUrl>dev</ManifestBaseUrl>
195+
</PropertyGroup>
196+
197+
<ItemGroup>
198+
<PackageReference Include="BlazorPWA.MSBuild" Version="1.0.1-beta20191206-002218">
199+
<PrivateAssets>all</PrivateAssets>
200+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
201+
</PackageReference>
202+
</ItemGroup>
203+
204+
</Project>
205+
```
206+
This project file use **`ManifestForce`** and **`ServiceWorkerForce`** to ensure that the **manifest.json** and **ServiceWorker.js** files are rebuilt - otherwise they would not change when you changed configuration.
207+
174208
## Roadmap
175209

176210
- [ ] At the moment, there is only one choice for caching strategy - Cache First/Network Fallback - I will add more (https://developers.google.com/web/ilt/pwa/introduction-to-progressive-web-app-architectures#caching_strategies_supported_by_sw-toolbox)

0 commit comments

Comments
 (0)