使用Angular CLI创建的PWA部署到Heroku的操作
起初
如果您还没有看过之前投稿的PWA应用的文章,现在准备部署,请点击以下链接查看:
(https://qiita.com/KashikomaSweet/items/a156e2c2468017359df0)
部署到Heroku
参考这篇文章,在Heroku上部署应用。
操作步骤
添加文件
添加 server.js
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/dist/pwa-sample'));
app.listen(process.env.PORT || 8080);
const path = require('path');
app.get('/*', function(req, res){
res.sendFile(path.join(__dirname + '/dist/pwa-sample/index.html'));
});
编辑文件
编辑package.json
{
"name": "pwa-sample",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node server.js",
"postinstall": "ng build --prod && node generate-sw.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.0.0",
"@angular/common": "~7.0.0",
"@angular/compiler": "~7.0.0",
"@angular/core": "~7.0.0",
"@angular/forms": "~7.0.0",
"@angular/http": "~7.0.0",
"@angular/platform-browser": "~7.0.0",
"@angular/platform-browser-dynamic": "~7.0.0",
"@angular/router": "~7.0.0",
"core-js": "^2.5.4",
"rxjs": "~6.3.3",
"workbox-build": "^3.6.3",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.10.0",
"@angular/cli": "~7.0.2",
"@angular/compiler-cli": "~7.0.0",
"@angular/language-service": "~7.0.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.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",
"typescript": "~3.1.1"
},
"engines": {
"node": "8.9.4",
"npm": "5.6.x"
}
}
我正在调整start、postinstall和engines。
请输入heroku支持的engines版本。
https://devcenter.heroku.com/articles/nodejs-support
在Heroku上创建应用程序。
首先安装herokuCLI。请访问https://devcenter.heroku.com/articles/heroku-cli。
只需要一个选项,将以下内容用中文进行释义:
从Heroku的仪表盘创建一个应用程序
点击右上方的“新建”按钮,然后选择“创建新应用程序”。
创建完后应会自动跳转到“部署”页面。
然后,只需按照该页面上的命令进行操作
(其中(cd my-project/ 部分应替换为先前创建的项目的目录)。
在电脑上访问后,即使离线也能显示出来,而在iPhone上访问后添加到主屏幕就应该变成了PWA。
将来的目标
我打算在未来学习Angular并且希望能够扩展这个PWASAMPLE。(努力目标)