Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/template/README.md b/template/README.md
- index f7a1c4f..c0b0f26 100644
- --- a/template/README.md
- +++ b/template/README.md
- @@ -1,6 +1,6 @@
- -# Quasar App
- +# Quasar PWA App
- -> A Quasar project
- +> A Quasar PWA project
- ## Build Setup
- @@ -8,7 +8,7 @@
- # install dependencies
- $ npm install
- -# serve with hot reload at localhost:8080
- +# serve with hot reload at localhost:8081
- $ quasar dev
- # build for production with minification
- diff --git a/template/build/fs-utils.js b/template/build/fs-utils.js
- new file mode 100644
- index 0000000..92e6c0e
- --- /dev/null
- +++ b/template/build/fs-utils.js
- @@ -0,0 +1,13 @@
- +var fs = require('fs')
- +var UglifyJS = require('uglify-es')
- +
- +module.exports = {
- + loadMinified: function (filePath) {
- + var code = fs.readFileSync(filePath, 'utf-8')
- + var result = UglifyJS.minify(code)
- + if (result.error) {
- + return ''
- + }
- + return result.code
- + }
- +}
- diff --git a/template/build/script.build.js b/template/build/script.build.js
- index 31758c0..2e1b37d 100644
- --- a/template/build/script.build.js
- +++ b/template/build/script.build.js
- @@ -3,7 +3,6 @@ process.env.NODE_ENV = 'production'
- require('colors')
- var
- - shell = require('shelljs'),
- path = require('path'),
- env = require('./env-utils'),
- css = require('./css-utils'),
- @@ -19,9 +18,6 @@ console.log(' building for Cordova or Electron.\n')
- require('./script.clean.js')
- console.log((' Building Quasar App with "' + env.platform.theme + '" theme...\n').bold)
- -shell.mkdir('-p', targetPath)
- -shell.cp('-R', 'src/statics', targetPath)
- -
- function finalize () {
- console.log((
- '\n Build complete with "' + env.platform.theme.bold + '" theme in ' +
- diff --git a/template/build/service-worker-dev.js b/template/build/service-worker-dev.js
- new file mode 100644
- index 0000000..979e196
- --- /dev/null
- +++ b/template/build/service-worker-dev.js
- @@ -0,0 +1,17 @@
- +// This service worker file is effectively a 'no-op' that will reset any
- +// previous service worker registered for the same host:port combination.
- +// In the production build, this file is replaced with an actual service worker
- +// file that will precache your site's local assets.
- +// See https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
- +
- +self.addEventListener('install', () => self.skipWaiting());
- +
- +self.addEventListener('activate', () => {
- + self.clients.matchAll({ type: 'window' }).then(windowClients => {
- + for (let windowClient of windowClients) {
- + // Force open pages to refresh, so that they have a chance to load the
- + // fresh navigation response from the local dev server.
- + windowClient.navigate(windowClient.url);
- + }
- + });
- +});
- \ No newline at end of file
- diff --git a/template/build/service-worker-prod.js b/template/build/service-worker-prod.js
- new file mode 100644
- index 0000000..dd6f006
- --- /dev/null
- +++ b/template/build/service-worker-prod.js
- @@ -0,0 +1,55 @@
- +(function() {
- + 'use strict';
- +
- + // Check to make sure service workers are supported in the current browser,
- + // and that the current page is accessed from a secure origin. Using a
- + // service worker from an insecure origin will trigger JS console errors.
- + const isLocalhost = Boolean(window.location.hostname === 'localhost' ||
- + // [::1] is the IPv6 localhost address.
- + window.location.hostname === '[::1]' ||
- + // 127.0.0.1/8 is considered localhost for IPv4.
- + window.location.hostname.match(
- + /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
- + )
- + );
- +
- + window.addEventListener('load', function() {
- + if ('serviceWorker' in navigator &&
- + (window.location.protocol === 'https:' || isLocalhost)) {
- + navigator.serviceWorker.register('service-worker.js')
- + .then(function(registration) {
- + // updatefound is fired if service-worker.js changes.
- + registration.onupdatefound = function() {
- + // updatefound is also fired the very first time the SW is installed,
- + // and there's no need to prompt for a reload at that point.
- + // So check here to see if the page is already controlled,
- + // i.e. whether there's an existing service worker.
- + if (navigator.serviceWorker.controller) {
- + // The updatefound event implies that registration.installing is set
- + const installingWorker = registration.installing;
- +
- + installingWorker.onstatechange = function() {
- + switch (installingWorker.state) {
- + case 'installed':
- + // At this point, the old content will have been purged and the
- + // fresh content will have been added to the cache.
- + // It's the perfect time to display a "New content is
- + // available; please refresh." message in the page's interface.
- + break;
- +
- + case 'redundant':
- + throw new Error('The installing ' +
- + 'service worker became redundant.');
- +
- + default:
- + // Ignore
- + }
- + };
- + }
- + };
- + }).catch(function(e) {
- + console.error('Error during service worker registration:', e);
- + });
- + }
- + });
- +})();
- diff --git a/template/build/webpack.base.conf.js b/template/build/webpack.base.conf.js
- index 8fff6ef..d42105a 100644
- --- a/template/build/webpack.base.conf.js
- +++ b/template/build/webpack.base.conf.js
- @@ -59,7 +59,13 @@ module.exports = {
- loaders: merge({js: 'babel-loader'}, cssUtils.styleLoaders({
- sourceMap: useCssSourceMap,
- extract: env.prod
- - }))
- + })),
- + transformToRequire: {
- + video: 'src',
- + source: 'src',
- + img: 'src',
- + image: 'xlink:href'
- + }
- }
- },
- {
- diff --git a/template/build/webpack.dev.conf.js b/template/build/webpack.dev.conf.js
- index b4dd19e..4c3d8d1 100644
- --- a/template/build/webpack.dev.conf.js
- +++ b/template/build/webpack.dev.conf.js
- @@ -1,4 +1,6 @@
- var
- + fs = require('fs'),
- + path = require('path'),
- config = require('../config'),
- webpack = require('webpack'),
- merge = require('webpack-merge'),
- @@ -31,13 +33,12 @@ module.exports = merge(baseWebpackConfig, {
- new HtmlWebpackPlugin({
- filename: 'index.html',
- template: 'src/index.html',
- - inject: true
- + inject: true,
- + serviceWorkerLoader: `<script>${fs.readFileSync(path.join(__dirname,
- + './service-worker-dev.js'), 'utf-8')}</script>`
- }),
- new FriendlyErrorsPlugin({
- clearConsole: config.dev.clearConsoleOnRebuild
- })
- - ],
- - performance: {
- - hints: false
- - }
- + ]
- })
- diff --git a/template/build/webpack.prod.conf.js b/template/build/webpack.prod.conf.js
- index c25411b..f8f5bc5 100644
- --- a/template/build/webpack.prod.conf.js
- +++ b/template/build/webpack.prod.conf.js
- @@ -7,7 +7,10 @@ var
- baseWebpackConfig = require('./webpack.base.conf'),
- ExtractTextPlugin = require('extract-text-webpack-plugin'),
- HtmlWebpackPlugin = require('html-webpack-plugin'),
- - OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
- + OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin'),
- + CopyWebpackPlugin = require('copy-webpack-plugin'),
- + SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin'),
- + fsUtils = require('./fs-utils')
- module.exports = merge(baseWebpackConfig, {
- module: {
- @@ -49,7 +52,9 @@ module.exports = merge(baseWebpackConfig, {
- // https://github.com/kangax/html-minifier#options-quick-reference
- },
- // necessary to consistently work with multiple chunks via CommonsChunkPlugin
- - chunksSortMode: 'dependency'
- + chunksSortMode: 'dependency',
- + serviceWorkerLoader: `<script>${fsUtils.loadMinified(path.join(__dirname,
- + './service-worker-prod.js'))}</script>`
- }),
- // split vendor js into its own file
- new webpack.optimize.CommonsChunkPlugin({
- @@ -73,6 +78,22 @@ module.exports = merge(baseWebpackConfig, {
- new webpack.optimize.CommonsChunkPlugin({
- name: 'manifest',
- chunks: ['vendor']
- + }),
- + // copy custom static assets
- + new CopyWebpackPlugin([
- + {
- + from: path.resolve(__dirname, '../src/statics'),
- + to: 'statics',
- + ignore: ['.*']
- + }
- + ]),
- + // service worker caching
- + new SWPrecacheWebpackPlugin({
- + cacheId: 'my-quasar-app',
- + filename: 'service-worker.js',
- + staticFileGlobs: ['dist/**/*.{js,html,css,woff,svg}'],
- + minify: true,
- + stripPrefix: 'dist/'
- })
- ]
- })
- diff --git a/template/config/index.js b/template/config/index.js
- index 89c2580..9d07490 100644
- --- a/template/config/index.js
- +++ b/template/config/index.js
- @@ -32,7 +32,7 @@ module.exports = {
- // auto open browser or not
- openBrowser: true,
- publicPath: '/',
- - port: 8080,
- + port: 8081,
- // If for example you are using Quasar Play
- // to generate a QR code then on each dev (re)compilation
- diff --git a/template/package.json b/template/package.json
- index 22ab124..0e22a06 100644
- --- a/template/package.json
- +++ b/template/package.json
- @@ -26,6 +26,7 @@
- "babel-preset-stage-2": "^6.0.0",
- "colors": "^1.1.2",
- "connect-history-api-fallback": "^1.1.0",
- + "copy-webpack-plugin": "^4.0.1",
- "css-loader": "^0.28.0",
- "es6-promise": "^4.1.1",
- "eslint": "^4.4.1",
- @@ -54,6 +55,8 @@
- "shelljs": "^0.7.0",
- "stylus": "^0.54.5",
- "stylus-loader": "^3.0.1",
- + "sw-precache-webpack-plugin": "^0.11.4",
- + "uglify-es": "^3.0.28",
- "url-loader": "^0.5.7",
- "vue-loader": "~12.2.2",
- "vue-style-loader": "^3.0.1",
- diff --git a/template/src/index.html b/template/src/index.html
- index 4e7bfd2..d961466 100644
- --- a/template/src/index.html
- +++ b/template/src/index.html
- @@ -1,16 +1,40 @@
- <!DOCTYPE html>
- -<html>
- +<html lang="en">
- <head>
- <meta charset="utf-8">
- + <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="format-detection" content="telephone=no">
- <meta name="msapplication-tap-highlight" content="no">
- - <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
- + <meta name="viewport" content="width=device-width, initial-scale=1">
- - <title>Quasar App</title>
- - <link rel="icon" href="statics/quasar-logo.png" type="image/x-icon">
- + <title>Quasar PWA App</title>
- + <link rel="icon" type="image/png" sizes="32x32" href="<%= htmlWebpackPlugin.files.publicPath %>statics/icons/favicon-32x32.png">
- + <link rel="icon" type="image/png" sizes="16x16" href="<%= htmlWebpackPlugin.files.publicPath %>statics/icons/favicon-16x16.png">
- + <link rel="manifest" href="<%= htmlWebpackPlugin.files.publicPath %>statics/manifest.json">
- +
- + <!-- Add to home screen for Safari on iOS -->
- + <meta name="apple-mobile-web-app-capable" content="yes">
- + <meta name="apple-mobile-web-app-status-bar-style" content="white">
- + <meta name="apple-mobile-web-app-title" content="Quasar App">
- + <link rel="apple-touch-icon" href="<%= htmlWebpackPlugin.files.publicPath %>statics/icons/apple-icon-152x152.png">
- + <!-- Add to home screen for Windows -->
- + <meta name="msapplication-TileImage" content="<%= htmlWebpackPlugin.files.publicPath %>statics/icons/ms-icon-144x144.png">
- + <meta name="msapplication-TileColor" content="#ffffff">
- +
- + <meta name="theme-color" content="#027be3">
- +
- + <% for (var chunk of webpack.chunks) {
- + for (var file of chunk.files) {
- + if (file.match(/\.(js|css)$/)) { %>
- + <link rel="<%= chunk.initial?'preload':'prefetch' %>" href="<%= htmlWebpackPlugin.files.publicPath + file %>" as="<%= file.match(/\.css$/)?'style':'script' %>"><% }}} %>
- </head>
- <body>
- + <noscript>
- + This is your fallback content in case JavaScript fails to load.
- + </noscript>
- <div id="q-app"></div>
- + <!-- Todo: only include in production -->
- + <%= htmlWebpackPlugin.options.serviceWorkerLoader %>
- <!-- built files will be auto injected -->
- </body>
- </html>
- diff --git a/template/src/main.js b/template/src/main.js
- index 1958813..c62777f 100644
- --- a/template/src/main.js
- +++ b/template/src/main.js
- @@ -18,18 +18,16 @@ Vue.config.productionTip = false
- Vue.use(Quasar) // Install Quasar Framework
- if (__THEME === 'mat') {
- - require('quasar-extras/roboto-font')
- + // require('quasar-extras/roboto-font')
- }
- -import 'quasar-extras/material-icons'
- +// import 'quasar-extras/material-icons'
- // import 'quasar-extras/ionicons'
- // import 'quasar-extras/fontawesome'
- // import 'quasar-extras/animate'
- -Quasar.start(() => {
- - /* eslint-disable no-new */
- - new Vue({
- - el: '#q-app',
- - router,
- - render: h => h(require('./App'))
- - })
- +/* eslint-disable no-new */
- +new Vue({
- + el: '#q-app',
- + router,
- + render: h => h(require('./App'))
- })
- diff --git a/template/src/router.js b/template/src/router.js
- index d21dc28..8c06c76 100644
- --- a/template/src/router.js
- +++ b/template/src/router.js
- @@ -1,12 +1,18 @@
- import Vue from 'vue'
- import VueRouter from 'vue-router'
- +import Hello from '@/Hello.vue'
- +
- Vue.use(VueRouter)
- +/*
- + * Uncomment this section and use "load()" if you want
- + * to lazy load routes.
- function load (component) {
- // '@' is aliased to src/components
- return () => import(`@/${component}.vue`)
- }
- +*/
- export default new VueRouter({
- /*
- @@ -22,9 +28,6 @@ export default new VueRouter({
- */
- routes: [
- - { path: '/', component: load('Hello') },
- -
- - // Always leave this last one
- - { path: '*', component: load('Error404') } // Not found
- + { path: '/', component: Hello }
- ]
- })
- diff --git a/template/src/statics/icons/apple-icon-152x152.png b/template/src/statics/icons/apple-icon-152x152.png
- new file mode 100644
- index 0000000..c918acd
- Binary files /dev/null and b/template/src/statics/icons/apple-icon-152x152.png differ
- diff --git a/template/src/statics/icons/favicon-16x16.png b/template/src/statics/icons/favicon-16x16.png
- new file mode 100644
- index 0000000..177c86e
- Binary files /dev/null and b/template/src/statics/icons/favicon-16x16.png differ
- diff --git a/template/src/statics/icons/favicon-32x32.png b/template/src/statics/icons/favicon-32x32.png
- new file mode 100644
- index 0000000..b8e6cdf
- Binary files /dev/null and b/template/src/statics/icons/favicon-32x32.png differ
- diff --git a/template/src/statics/icons/icon-192x192.png b/template/src/statics/icons/icon-192x192.png
- new file mode 100644
- index 0000000..2a9b50b
- Binary files /dev/null and b/template/src/statics/icons/icon-192x192.png differ
- diff --git a/template/src/statics/icons/icon-512x512.png b/template/src/statics/icons/icon-512x512.png
- new file mode 100644
- index 0000000..a57354e
- Binary files /dev/null and b/template/src/statics/icons/icon-512x512.png differ
- diff --git a/template/src/statics/icons/ms-icon-144x144.png b/template/src/statics/icons/ms-icon-144x144.png
- new file mode 100644
- index 0000000..b0880e8
- Binary files /dev/null and b/template/src/statics/icons/ms-icon-144x144.png differ
- diff --git a/template/src/statics/manifest.json b/template/src/statics/manifest.json
- new file mode 100644
- index 0000000..c98ebf6
- --- /dev/null
- +++ b/template/src/statics/manifest.json
- @@ -0,0 +1,20 @@
- +{
- + "name": "Quasar App",
- + "short_name": "Quasar-PWA",
- + "icons": [
- + {
- + "src": "/statics/icons/icon-192x192.png",
- + "sizes": "192x192",
- + "type": "image/png"
- + },
- + {
- + "src": "/statics/icons/icon-512x512.png",
- + "sizes": "512x512",
- + "type": "image/png"
- + }
- + ],
- + "start_url": "/index.html",
- + "display": "standalone",
- + "background_color": "#ffffff",
- + "theme_color": "#027be3"
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement