离子PWA部署 [英] Ionic PWA deploy

查看:94
本文介绍了离子PWA部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我的Ionic 2项目的Progressive Web App版本部署到Heroku,但它似乎不起作用。我正在尝试使用Ionic build browser --prod,然后部署www文件夹,但我没有收到Heroku的任何响应(似乎没有任何部署)

解决方案

您应该采取的步骤:


  1. 离子构建浏览器--prod - 创建要部署的main.js文件
  2. 转至.gitignore文件并删除www /所以git捡起它并添加这两行,以便平台浏览器文件夹被拾取

      platforms / * 
    !平台/浏览器/
    !平台/浏览器/ www
    !平台/浏览器/ www /插件


  3. 将这两个库添加到您的package.json中(不要忘记运行npm install)

    $ p $ connect:^ 3.5.0,
    serve-static:^ 1.11.1


  4. 在package.json的npm脚本中添加一个开始

     start:节点server.js


  5. 使用以下代码将server.js添加到您的项目文件夹中:

      var connect = require('connect'),
    serveStatic = require('serve-static');

    var app = connect();

    app.use(serveStatic(platforms / browser / www))
    app.listen(process.env.PORT || 5000);

    请注意,此代码仅适用于离子应用程序,而不适用于正常的角度应用程序。
    现在你可以在你的cmd中写入 npm start node server.js ,你可以测试看看它是如何运行的。

  6. 使用 git push heroku master 将你的代码提交给heroku git。请注意,您的远程列表上有heroku git。你可以做 git remote -v 来检查是否是这种情况。 可选 - 将www /文件夹放回.gitignore和 git rm --cached -r ./www 将它们从你的git中删除。这是为了让您的同事在您每次提交时都不会在main.js中合并冲突。对于平台/浏览器也是如此。

您应该看到heroku安装并在您的环境中部署了一个节点应用程序推送到他们的git



注意如果您使用Heroku,您可以使用Heroku构建而不是使用您的git。 https://github.com/heroku/heroku-builds


I'm trying to deploy a Progressive Web App version of my Ionic 2 project to Heroku but it doesn't seem to work. What I'm trying is to use "Ionic build browser --prod" and then deploy the www folder, but I'm not getting any response from Heroku (Seems that nothing has being deployed)

解决方案

The steps you are supposed to take:

  1. Ionic build browser --prod - creates the main.js file to be deployed
  2. Go to .gitignore file and remove the mentions of www/ so git picks it up and add these two lines so platforms browsers folder is picked up

    platforms/*
    !platforms/browser/
    !platforms/browser/www
    !platforms/browser/www/plugins
    

  3. Add these 2 libraries to your package.json (don't forget to run npm install)

    "connect": "^3.5.0",
    "serve-static": "^1.11.1"
    

  4. Add a start to your npm scripts in package.json

    "start": "node server.js"
    

  5. Add server.js to your project folder with the following code:

    var connect = require('connect'),
    serveStatic = require('serve-static');
    
    var app = connect();
    
    app.use(serveStatic("platforms/browser/www"))
    app.listen(process.env.PORT || 5000);
    

    Please note this code is only for ionic apps and not normal angular apps. At this point you can write npm start or node server.js in your cmd and you can test to see how it will run.

  6. Commit your code to heroku git using git push heroku master. Please note to have the heroku git on your remote list. You may do git remote -v to check if thats the case. If not get the url from the website and add it.

  7. Optional - Put the www/ folder back in .gitignore and git rm --cached -r ./www to delete them from your git. This is so your co workers wont have merge conflicts on your main.js everytime you commit. The same for platforms/browser.

You are supposed to see heroku installing and deployed a node application in your enviornment after pushing to their git

NOTE If you are using Heroku you could probably do this with Heroku builds rather than playing with your git. https://github.com/heroku/heroku-builds

这篇关于离子PWA部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆