Pwa offline application cache use APP in many practical applications will be used

Important plugin: workbox-webpack-plugin

Download and install

Introduce and use in webpack.config.js file configuration

add in plugins

new WorkboxWebpackPlugin.GenrateSW({clientClaim: true, skipWaiting: true})

Use, import service-worker in the entry file

// 判断浏览器是否支持,需要添加对应的逻辑
if('serviceWorker' in navigator) {
  window.addEventListener('load', fucntion() {
    navigator.serviceWorker.register("/service-workre.js").
    then(
      ()=>{},
      ()=>{}
    )
  })
}

service-worker needs to run on the server side
serve plugin
serve -s (directory) expose the directory files and create a service to access the project


万年打野易大师
1.5k 声望1.1k 粉丝