Skip to content

Commit fc7eebf

Browse files
Ismael Ramosiramos
authored andcommitted
feat(service workers): add service workers support
1 parent 4c760be commit fc7eebf

21 files changed

+239
-64
lines changed

README.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,34 +55,35 @@
5555

5656
## What's included
5757

58-
* CRUD: create, update and remove heroes with Firebase
59-
* Angular Universal (SSR)
60-
* Use of [preboot](https://github.com/angular/preboot) module to share state between browser and server
61-
* Security Headers using [helmet](https://helmetjs.github.io). Report [here](https://securityheaders.com/?q=https%3A%2F%2Fwww.angularexampleapp.com).
62-
* Internationalization with the official i18n. Separated builds for english and spanish.
63-
* Lazy loading modules
64-
* Example of Angular Resolver for Hero Detail
65-
* More logical directory structure (from [here](https://itnext.io/choosing-a-highly-scalable-folder-structure-in-angular-d987de65ec7))
66-
* Basic example library
67-
* Following the [best practices](https://angular.io/guide/styleguide)!
68-
* Search bar, to look for heroes
69-
* Custom loading page
70-
* Lazy loading images with [ng-lazyload-image](https://github.com/tjoskar/ng-lazyload-image)
71-
* Modal and toasts (snakbar)!
72-
* Scroll restoration and anchor examples
73-
* Responsive layout (flex layout module)
74-
* SASS (most common used functions and mixins) and BEM styles
75-
* Animations with [ng-animate](https://jiayihu.github.io/ng-animate/)
76-
* Angular Pipes
77-
* Interceptors and Events (Progress bar active, if a request is pending)
78-
* Scroll to first invalid input in forms. ([ngx-scroll-to-first-invalid](https://github.com/Ismaestro/ngx-scroll-to-first-invalid))
79-
* Modernizr (browser features detection)
80-
* Browser filter (Bowser) because of IE ^^
81-
* [Sentry](https://sentry.io)! (logs every error in the app)
82-
* Google Tag Manager
83-
* ES6 Promises and Observables
84-
* Unit tests with Jasmine and Karma including code coverage (Use of [ng-bullet](https://www.npmjs.com/package/ng-bullet), [karma-mocha-reporter](https://github.com/litixsoft/karma-mocha-reporter)) and [ng-mocks](https://github.com/ike18t/ng-mocks)
85-
* End-to-end tests with Protractor
58+
- [x] CRUD: create, update and remove heroes with Firebase
59+
- [x] Angular Universal (SSR)
60+
- [x] Use of [preboot](https://github.com/angular/preboot) module to share state between browser and server
61+
- [x] Security Headers using [helmet](https://helmetjs.github.io). Report [here](https://securityheaders.com/?q=https%3A%2F%2Fwww.angularexampleapp.com).
62+
- [x] Internationalization with the official i18n. Separated builds for english and spanish.
63+
- [x] Lazy loading modules
64+
- [x] Service Workers enabled!
65+
- [x] Example of Angular Resolver for Hero Detail
66+
- [x] More logical directory structure (from [here](https://itnext.io/choosing-a-highly-scalable-folder-structure-in-angular-d987de65ec7))
67+
- [x] Basic example library
68+
- [x] Following the [best practices](https://angular.io/guide/styleguide)!
69+
- [x] Search bar, to look for heroes
70+
- [x] Custom loading page
71+
- [x] Lazy loading images with [ng-lazyload-image](https://github.com/tjoskar/ng-lazyload-image)
72+
- [x] Modal and toasts (snakbar)!
73+
- [x] Scroll restoration and anchor examples
74+
- [x] Responsive layout (flex layout module)
75+
- [x] SASS (most common used functions and mixins) and BEM styles
76+
- [x] Animations with [ng-animate](https://jiayihu.github.io/ng-animate/)
77+
- [x] Angular Pipes
78+
- [x] Interceptors and Events (Progress bar active, if a request is pending)
79+
- [x] Scroll to first invalid input in forms. ([ngx-scroll-to-first-invalid](https://github.com/Ismaestro/ngx-scroll-to-first-invalid))
80+
- [x] Modernizr (browser features detection)
81+
- [x] Browser filter (Bowser) because of IE ^^
82+
- [x] [Sentry](https://sentry.io)! (logs every error in the app)
83+
- [x] Google Tag Manager
84+
- [x] ES6 Promises and Observables
85+
- [x] Unit tests with Jasmine and Karma including code coverage (Use of [ng-bullet](https://www.npmjs.com/package/ng-bullet), [karma-mocha-reporter](https://github.com/litixsoft/karma-mocha-reporter)) and [ng-mocks](https://github.com/ike18t/ng-mocks)
86+
- [x] End-to-end tests with Protractor
8687

8788
### Angular Ivy
8889

angular.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@
7171
"mergeStrategies": {
7272
"externals": "prepend"
7373
}
74-
}
74+
},
75+
"serviceWorker": true,
76+
"ngswConfigPath": "ngsw-config.json"
7577
},
7678
"configurations": {
7779
"en": {
@@ -213,7 +215,8 @@
213215
"glob": "CNAME",
214216
"input": "src/assets",
215217
"output": "/"
216-
}
218+
},
219+
"src/manifest.webmanifest"
217220
],
218221
"stylePreprocessorOptions": {
219222
"includePaths": [
@@ -348,4 +351,4 @@
348351
}
349352
},
350353
"defaultProject": "angularexampleapp"
351-
}
354+
}

ngsw-config.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
3+
"index": "/index.html",
4+
"assetGroups": [
5+
{
6+
"name": "app",
7+
"installMode": "prefetch",
8+
"resources": {
9+
"files": [
10+
"/favicon.ico",
11+
"/index.html",
12+
"/*.css",
13+
"/*.js"
14+
]
15+
}
16+
},
17+
{
18+
"name": "assets",
19+
"installMode": "lazy",
20+
"updateMode": "prefetch",
21+
"resources": {
22+
"files": [
23+
"/assets/**",
24+
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
25+
]
26+
}
27+
}
28+
]
29+
}

package-lock.json

Lines changed: 93 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
"@angular/platform-browser": "8.0.2",
5151
"@angular/platform-browser-dynamic": "8.0.2",
5252
"@angular/platform-server": "8.0.2",
53+
"@angular/pwa": "0.800.6",
5354
"@angular/router": "8.0.2",
55+
"@angular/service-worker": "8.0.2",
5456
"@angular/upgrade": "8.0.2",
5557
"@ismaestro/ngx-scroll-to-first-invalid": "3.0.0",
5658
"@nguniversal/common": "7.1.1",

server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ app.use(helmet.contentSecurityPolicy({
4747
],
4848
scriptSrc: [
4949
'\'self\'',
50+
'\'unsafe-inline\'',
5051
'http://*.googletagmanager.com',
5152
'https://*.google-analytics.com'
5253
]

src/app/app.browser.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import {NgModule} from '@angular/core';
22
import {REQUEST} from '@nguniversal/express-engine/tokens';
33
import {AppModule} from './app.module';
44
import {AppComponent} from './app.component';
5+
import {ServiceWorkerModule} from '@angular/service-worker';
6+
import {environment} from '../environments/environment';
57

68
export function getRequest(): any {
79
return {headers: {cookie: document.cookie}};
810
}
911

1012
@NgModule({
1113
imports: [
12-
AppModule
14+
AppModule,
15+
ServiceWorkerModule.register('ngsw-worker.js', {enabled: environment.production})
1316
],
1417
providers: [
1518
{

src/app/app.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
<router-outlet *ngIf="isOnline;else isOffline"></router-outlet>
44
<ng-template #isOffline>
55
<div>
6-
<p class="offline-error" i18n="@@offlineMessage">Without connection we can not load
7-
anything!&nbsp;&nbsp;&nbsp;</p><span>:&nbsp;)</span>
6+
<p class="offline-error" i18n="@@offlineMessage">Without connection we can not load anything!</p>
87
</div>
98
</ng-template>
109
</div>

src/app/configs/routes.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const routesNames = {
1515
};
1616

1717
export const RoutesConfig: any = {
18-
routesNames: routesNames,
18+
routesNames,
1919
routes: {
2020
home: `/${routesNames.home}`,
2121
error404: `/${routesNames.error404}`,

src/assets/icons/icon-128x128.png

1.22 KB
Loading

0 commit comments

Comments
 (0)