Summarize the problem:
I'm trying to deploy my Angular 6 App to Heroku and keep the progressive web app features. There's no service worker for the end build on Heroku.
Background:
I've built a local Sports Store app in Angular 6. I'm following the book Pro Angular 6, 3rd Edition. by Adam Freeman and have gotten the app to roughly the stage at the end of chapter 9.
GitHub repository of chapter 9: SportsStore
To create this as a PWA I've run
ng add @angular/pwa
I edited the generated ngsw-config.json
so it matches this shown below in Code
Following the blog post here I've done the following steps:
npm install --save express path
- edited
package.json
moving@angular/cli
,@angular/compiler-cli
,typescript
and@angular-devkit/build-angular": "~0.6.8"
from devDependencies over to dependencies - Created
server.js
- Created
Procfile
withweb: node server.js
heroku create sportsstoredemo
git add .
git commit -m "setup'
git push heroku master
This deploys on heroku but does not include the service worker. I'm lost what I can do as I barely understand the steps I've taken above.
Can someone take the GitHub repo and advise what steps will get this on Heroku with service worker running or point out where I have gone wrong?
Code
ngsw-config.json
{
"index": "/index.html",
"assetGroups": [{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js"
]
}
}, {
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/font/*"
]
}
}],
"dataGroups": [
{
"name": "api-product",
"urls": ["/api/products"],
"cacheConfig" : {
"maxSize": 100,
"maxAge": "5d"
}
}],
"navigationUrls": [
"/**"
]
}
package.json
{
"name": "sports-store",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"json": "json-server data.js -p 3500 -m authMiddleware.js",
"postinstall": "ng build --prod"
},
"engines": {
"node": "10.15.3",
"npm": "6.4.1"
},
"private": true,
"dependencies": {
"@angular-devkit/build-angular": "~0.13.0",
"@angular/cli": "~7.3.6",
"@angular/compiler-cli": "~7.2.0",
"typescript": "~3.2.2",
"@angular/animations": "~7.2.0",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "~7.2.0",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/pwa": "^0.12.4",
"@angular/router": "~7.2.0",
"@angular/service-worker": "~7.2.0",
"bootstrap": "^4.3.1",
"core-js": "^2.5.4",
"express": "^4.16.4",
"font-awesome": "^4.7.0",
"path": "^0.12.7",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular/language-service": "~7.2.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"json-server": "^0.14.2",
"jsonwebtoken": "^8.5.1",
"karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0"
}
}
server.js
const path = require('path');
const express = require('express');
const app = express();
// Serve static files
app.use(express.static(__dirname + '/dist/MY_APP_NAME'));
// Send all requests to index.html
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/MY_APP_NAME/index.html'));
});
// default Heroku port
app.listen(process.env.PORT || 5000);
Describe expected and actual results
Expected - same app as code SportsStore but running as PWA on Heroku
Actual - just Angular App only when built on Heroku. Locally I can get this running as PWA.