Skip to content

Commit a360354

Browse files
Merge pull request #1 from SQL-MisterMagoo/feature_ssb
Add SSB support
2 parents babddbf + e7f004d commit a360354

8 files changed

+55
-18
lines changed

Blazor.PWA.MSBuild.Tasks/Blazor.PWA.MSBuild.Tasks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ I will add more network caching strategies, but for now it has just one - cache
6969
</ItemGroup>
7070

7171
<ItemGroup>
72+
<None Remove="Templates\ServiceWorker\sw_fetch-none.template.js" />
7273
<None Remove="Templates\ServiceWorker\sw_register-beforeinstallprompt.template.js" />
7374
<None Remove="Templates\ServiceWorker\sw_register-installable-banner.template.js" />
7475
<None Remove="Templates\ServiceWorker\sw_register-installable-blazor.template.js" />
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
self.addEventListener(networkFetchEvent, event => {
2+
return fetch(event.request);
3+
});

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@
7171

7272
<!-- Add manifest to index.html -->
7373
<PropertyGroup>
74-
<IndexFile>$(WWWRoot)$(ServiceWorkerIndexUrl)</IndexFile>
74+
<IndexFile Condition="'$(BlazorProjectType)' == 'CSB'">$(WWWRoot)$(ProjectIndexPage)</IndexFile>
75+
<IndexFile Condition="'$(BlazorProjectType)' == 'SSB'">$(ProjectHomePage)</IndexFile>
7576
<IndexLines>$([System.IO.File]::ReadAllText($(IndexFile)))</IndexLines>
7677
</PropertyGroup>
77-
78+
<Message Importance="high" Text="Blazor Project Type detected as $(BlazorProjectType)"/>
7879
<Message Importance="high" Text="Adding manifest to $(IndexFile)"
7980
Condition="'$(IndexLines.Contains(rel=&quot;manifest&quot;))'=='false'"/>
8081

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,26 @@
4848
</ServiceWorkerPreCacheGeneratedFiles>
4949

5050
<!-- Setup the declarations for the Service Worker -->
51-
<ServiceWorkerConstants Condition="'$(ServiceWorkerConstants)' == ''">
51+
<ServiceWorkerConstants Condition="'$(ServiceWorkerConstants)' == '' AND '$(BlazorProjectType)' == 'CSB'">
5252
const baseURL = '$(ServiceWorkerBaseURL)'%3B;
53-
const indexURL = '$(ServiceWorkerBaseUrl)$(ServiceWorkerIndexURL)'%3B;
53+
const indexURL = '$(ServiceWorkerBaseUrl)$(ProjectIndexPage)'%3B;
5454
const networkFetchEvent = '$(ServiceWorkerNetworkFetchEvent)'%3B;
5555
const swInstallEvent = '$(ServiceWorkerInstallEvent)'%3B;
5656
const swInstalledEvent = '$(ServiceWorkerInstalledEvent)'%3B;
5757
const swActivateEvent = '$(ServiceWorkerActivateEvent)'%3B;
5858
const staticCachePrefix = '$(ServiceWorkerCacheName)-v'%3B;
5959
const staticCacheName = '$(ServiceWorkerCacheName)-v$(ServiceWorkerCacheVersion)'%3B;
6060
</ServiceWorkerConstants>
61+
62+
<!-- Setup the declarations for the Service Worker -->
63+
<ServiceWorkerConstants Condition="'$(ServiceWorkerConstants)' == '' AND '$(BlazorProjectType)' == 'SSB'">
64+
const baseURL = '$(ServiceWorkerBaseURL)'%3B;
65+
const indexURL = '$(ServiceWorkerBaseUrl)$(ProjectHomePage)'%3B;
66+
const networkFetchEvent = '$(ServiceWorkerNetworkFetchEvent)'%3B;
67+
const swInstallEvent = '$(ServiceWorkerInstallEvent)'%3B;
68+
const swInstalledEvent = '$(ServiceWorkerInstalledEvent)'%3B;
69+
const swActivateEvent = '$(ServiceWorkerActivateEvent)'%3B;
70+
</ServiceWorkerConstants>
6171
</PropertyGroup>
6272

6373
<!-- The "Templates" properties are used to define where to find templates for the service worker sections -->
@@ -69,7 +79,7 @@
6979
<!-- The file that contains template code for the network fetch event in the service worker -->
7080
<ServiceWorkerTemplateNetwork Condition="'$(ServiceWorkerTemplateNetwork)' == ''">$(ServiceWorkerTemplatePath)sw_$(ServiceWorkerNetworkFetchEvent)-$(ServiceWorkerPattern).template.js</ServiceWorkerTemplateNetwork>
7181
</PropertyGroup>
72-
<Message Importance="high" Text="Exclude:;@(ServiceWorkerPreCacheExcludeFiles);@(ServiceWorkerPreCacheExcludeReleaseFiles);"/>
82+
7383
<ItemGroup>
7484
<!-- Build a list of files to pre-cache -->
7585
<DistFiles Include="$(ServiceWorkerPreCacheIncludeFiles);" />
@@ -92,10 +102,12 @@
92102
<WriteLinesToFile File="$(WWWRoot)$(ServiceWorkerFileName)"
93103
Overwrite="true"
94104
Lines="$(ServiceWorkerConstants)" />
95-
<WriteLinesToFile File="$(WWWRoot)$(ServiceWorkerFileName)"
105+
<WriteLinesToFile Condition="'$(BlazorProjectType)' == 'CSB'"
106+
File="$(WWWRoot)$(ServiceWorkerFileName)"
96107
Overwrite="false"
97108
Lines="const requiredFiles = [;@(DistFiles -> '&quot;/%(RecursiveDir)%(FileName)%(Extension)&quot;'->Replace('\','/'),',%0D%0A');]%3B;" />
98-
<WriteLinesToFile File="$(WWWRoot)$(ServiceWorkerFileName)"
109+
<WriteLinesToFile Condition="'$(BlazorProjectType)' == 'CSB'"
110+
File="$(WWWRoot)$(ServiceWorkerFileName)"
99111
Overwrite="false"
100112
Lines="@(InstallTemplateLines);" />
101113
<WriteLinesToFile File="$(WWWRoot)$(ServiceWorkerFileName)"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@
9393
<Target Name="_ServiceWorkerUpdateIndex">
9494
<!-- Add ServiceWorkerRegister.js to index.html -->
9595
<PropertyGroup>
96-
<IndexFile>$(WWWRoot)$(ServiceWorkerIndexUrl)</IndexFile>
96+
<IndexFile Condition="'$(BlazorProjectType)' == 'CSB'">$(WWWRoot)$(ProjectIndexPage)</IndexFile>
97+
<IndexFile Condition="'$(BlazorProjectType)' == 'SSB'">$(ProjectHomePage)</IndexFile>
9798
<IndexLines>$([System.IO.File]::ReadAllText($(IndexFile)))</IndexLines>
9899
</PropertyGroup>
99100

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
<Import Project="..\build\BlazorPWA.MSBuild.ServiceWorkerRegister.targets" />
55
<Import Project="..\build\BlazorPWA.MSBuild.Manifest.targets" />
66

7+
<PropertyGroup Label="ProjectTypes">
8+
<!-- Project type -->
9+
<BlazorProjectType Condition="'$(BlazorProjectType)' == '' AND '$(TargetFramework)' == 'netcoreapp3.1'">SSB</BlazorProjectType>
10+
<BlazorProjectType Condition="'$(BlazorProjectType)' == '' AND '$(TargetFramework)' == 'netcoreapp3.0'">SSB</BlazorProjectType>
11+
<BlazorProjectType Condition="'$(BlazorProjectType)' == '' AND '$(TargetFramework)' == 'netstandard2.0'">CSB</BlazorProjectType>
12+
</PropertyGroup>
13+
714
<PropertyGroup Label="ServiceWorker">
815
<!-- The service worker file names to generate -->
916
<ServiceWorkerFileName Condition="'$(ServiceWorkerFileName)' == ''">ServiceWorker.js</ServiceWorkerFileName>
1017
<ServiceWorkerRegisterFileName Condition="'$(ServiceWorkerRegisterFileName)' == ''">ServiceWorkerRegister.js</ServiceWorkerRegisterFileName>
1118

1219
<!-- The PWA strategy to implement in the service worker -->
13-
<!-- Currently only supports offline-first -->
20+
<!-- Currently only supports offline-first or none -->
21+
<ServiceWorkerPattern Condition="'$(BlazorProjectType)' == 'CSB' AND '$(ServiceWorkerPattern)' == ''">offline-first</ServiceWorkerPattern>
22+
<ServiceWorkerPattern Condition="'$(BlazorProjectType)' == 'SSB' AND '$(ServiceWorkerPattern)' == ''">none</ServiceWorkerPattern>
1423
<ServiceWorkerPattern Condition="'$(ServiceWorkerPattern)' == ''">offline-first</ServiceWorkerPattern>
15-
<!-- Remove this when we implement more patterns -->
16-
<ServiceWorkerPattern>offline-first</ServiceWorkerPattern>
1724

1825
<!-- The Cache name and version together form the name of the application browser cache e.g. blazor-cache-v1 -->
1926
<ServiceWorkerCacheName Condition="'$(ServiceWorkerCacheName)' == ''">blazor-cache</ServiceWorkerCacheName>
@@ -22,8 +29,11 @@
2229
<!-- The "home route" url for the application -->
2330
<ServiceWorkerBaseUrl Condition="'$(ServiceWorkerBaseUrl)' == ''">/</ServiceWorkerBaseUrl>
2431

25-
<!-- The actual home page served up for the base URL - so we have a way to cache it -->
26-
<ServiceWorkerIndexUrl Condition="'$(ServiceWorkerIndexUrl)' == ''">index.html</ServiceWorkerIndexUrl>
32+
<!-- The CSB home page served up for the base URL -->
33+
<ProjectIndexPage Condition="'$(ProjectIndexPage)' == ''">index.html</ProjectIndexPage>
34+
35+
<!-- The SSB home page served up for the base URL -->
36+
<ProjectHomePage Condition="'$(ProjectHomePage)' == ''">Pages/_Host.cshtml</ProjectHomePage>
2737

2838
</PropertyGroup>
2939

@@ -54,7 +64,7 @@
5464
BeforeTargets="$(CreatePWABeforeTargets)"
5565
Condition="'$(ServiceWorkerPattern)'!='' AND '$(ServiceWorkerCacheName)'!='' AND '$(ServiceWorkerCacheVersion)'!='' AND (!Exists('$(WWWRoot)$(ServiceWorkerFileName)') OR '$(ServiceWorkerForce)'=='true')">
5666

57-
<Message Importance="high" Text="Building Your PWA: Type: $(ServiceWorkerPattern) CacheName: $(ServiceWorkerCacheName) CacheVersion: $(ServiceWorkerCacheVersion)"/>
67+
<Message Importance="high" Text="Building Your $(BlazorProjectType) PWA: Type: $(ServiceWorkerPattern) CacheName: $(ServiceWorkerCacheName) CacheVersion: $(ServiceWorkerCacheVersion)"/>
5868
<CallTarget Targets="BuildServiceWorkerInstaller"/>
5969
<CallTarget Targets="BuildServiceWorkerManifest"/>
6070
<CallTarget Targets="BuildServiceWorker"/>

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
#### 16/10/2019
2+
3+
- Added new **Property** **`BlazorProjectType`** - used to select the type of Blazor project (SSB/CSB). This property will auto-configure but can be overridden in your csproj file in cases where auto-configure is wrong.
4+
- Added new **ServiceWorkerPattern** value - "none" - primarily intended for SSB projects (where it is the default) - this service worker does nothing.
5+
- Removed **Property** **`ServiceWorkerIndexUrl`**
6+
- Added new **Property** **`ProjectIndexPage`** - used to identify the name of a _CSB_ index page - defaults to `index.html`
7+
- Added new **Property** **`ProjectHomePage`** - used to identify the name of a _SSB_ index page - defaults to `Pages\_Host.cshtml`
8+
- Added **`BlazorProjectType`** to build output.
9+
110
#### 10/08/2019 - 13/08/2019
211

312
- Added new **Property** **`ServiceWorkerUpdateAlertText`** - used to change the default text in the "Update available alert".

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Blazor PWA Builder - MSBuild
22

3-
The easiest way to turn your Client Side Blazor project into a Progressive Web App (PWA).
3+
The easiest way to turn your Server Side And Client Side Blazor projects into Progressive Web Apps (PWA).
44

55
This project, when added to your build process, will generate the required files to enable basic PWA abilities for your project.
66

7-
It generates a manifest.json, a Service Worker with pre-caching of all required files and an installer for the Service Worker.
7+
It generates a manifest.json, a Service Worker with pre-caching of all required files (Blazor WebAssembly only) and an installer for the Service Worker.
88

9-
It currently includes a simple banner to notify the user that your application can be installed, and a simple alert to notify users when your application has been updated.
9+
It currently includes a simple banner, by default, to notify the user that your application can be installed, and a simple alert to notify users when your application has been updated (CSB Only).
1010

11-
This is to be considered a Beta release - I am looking for feedback/issues/requests.
11+
This is now an official release - I am looking for feedback/issues/requests.
1212

1313
### Browser compatibility
1414

0 commit comments

Comments
 (0)