Python3, Vue-cli 3.0, node.js 8
Demo: https://flask-vue-pwa.herokuapp.com
- Front-end: Vue.js
- Back-end: Flask
- PWA ready: support install app; offline view
- read to deploy to Heroku
-
cd flask-vue-pwa
-
python3 -m venv venv
-
Linux: source venv/bin/activate Windows: venv\Scripts\activate
-
pip install Flask
-
flask run Open browser: http://localhost:5000 to view
- develop your front-end pages in
/src
- preview:
npm run serve
- build:
npm run build
- copy all files in
/dist
to Flask/static
- copy
index.html
to Flask/templates
copy-webpack-plugin
will auto copy files (Windows only. For Linux, pls modifypackage.json - Scripts
by yourself)- ready to deploy Note: when deploy to server, need to use HTTPS! Otherwise, service-worker won't work.
- modification of Flask template
- Flask need to set app parameter
static_url_path
to ''. This is due to PWAmanifest.json
andservice-worker.js
etc. files required to be accessed in / root url. Set to '' empty, means when client requesting files in root url:http://my.site/manifest.json
, Flask will search in default static directory (i.e./static
). If not setstatic_url_path
, client requesting url is:http://my.site/static/manifest.json
# app.py
app = Flask(__name__, static_url_path='')
-
Vue CLI 3.0 vue.config.js You need to manually create
/vue.config.js
if need special configurtions -
service-worker.js Add your customized registerRoute, strategies in
/src/service-worker.js
. Including 'offline.html' and '404.html'
- Click 'Article ?', will return customized
404
page - disconnect network, click 'Article 1', will return customized
offline
page