vue/cli@3.x项目pwa处理

前言

  1. 什么是pwa?
    Progressive Web Apps,渐进式 Web 应用
    pwa是我们在追求webapp便捷和原生应用良好体验结合的过程中的产物,目前兼容性是最大障碍
    底层使用的是workBox (service worker的一个框架),封装了各种api和缓存策略,
    vue-cli3.0集成的是workbox-webpack-plagin,我们可以通过vue.config.js的pwa配置项进行配置

  2. pwa 特征?
    具有可离线、添加到桌面(一级入口)、后台同步、服务端推送等特征

使用

  1. 新项目中如何集成?
    可直接通过 vue/cli 脚手架添加 pwa模块;
    vue集成的@vue/cli-plugin-pwa 模块会自动在项目/src下生成registerServiceWorker.js 文件
    内容如下:
/* eslint-disable no-console */

import {
    register } from 'register-service-worker'

if (process.env.NODE_ENV === 'production') {
   
  register(`${
     process.env.BASE_URL}service-worker.js`, {
   
    ready () {
   
      console.log(
        'App is being served from cache by a service worker.\n' +
        'For more details, visit https://goo.gl/AFskqB'
      )
    },
    registered () {
   
      console.log('Service worker has been registered.')
    },
    cached () {
   
      console.log('Content has been cached for offline use.')
    },
    updatefound () {
   
      console.log('New content is downloading.')
    },
    updated () {
   
      console.log('New content is available; please refresh.')
    },
    offline () {
   
      console.log('No internet connection found. App is running in offline mode.')
    },
    
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @vue/cli-plugin-vuex@4.4.6 npm ERR! Found: @vue/cli-service@5.0.8 npm ERR! node_modules/@vue/cli-service npm ERR! dev @vue/cli-service@"^5.0.8" from the root project npm ERR! peer @vue/cli-service@"^3.0.0 || ^4.0.0 || ^5.0.0-0" from @vue/cli-plugin-babel@5.0.8 npm ERR! node_modules/@vue/cli-plugin-babel npm ERR! dev @vue/cli-plugin-babel@"^5.0.8" from the root project npm ERR! 3 more (@vue/cli-plugin-pwa, @vue/cli-plugin-router, @vue/cli-plugin-vuex) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-vuex@4.4.6 npm ERR! node_modules/@vue/cli-plugin-vuex npm ERR! dev @vue/cli-plugin-vuex@"~4.4.0" from the root project npm ERR! npm ERR! Conflicting peer dependency: @vue/cli-service@4.5.19 npm ERR! node_modules/@vue/cli-service npm ERR! peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-vuex@4.4.6 npm ERR! node_modules/@vue/cli-plugin-vuex npm ERR! dev @vue/cli-plugin-vuex@"~4.4.0" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! npm ERR! For a full report see: npm ERR! C:\Users\35514\AppData\Local\npm-cache\_logs\2023-06-08T07_30_06_817Z-eresolve-report.txt npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\35514\AppData\Local\npm-cache\_logs\2023-06-08T07_30_06_817Z-debug-0.log
06-09
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值