【发布时间】:2019-06-19 01:30:18
【问题描述】:
我使用 webpack 离线插件制作了一个 PWA,配置如下:
// Put it in the end to capture all the HtmlWebpackPlugin's
// assets manipulations and do leak its manipulations to HtmlWebpackPlugin
new OfflinePlugin({
ServiceWorker: {
events: true,
},
relativePaths: false,
publicPath: '/',
appShell: '/',
// No need to cache .htaccess. See http://mxs.is/googmp,
// this is applied before any match in `caches` section
excludes: ['.htaccess'], // index.html
caches: {
main: [':rest:'],
// All chunks marked as `additional`, loaded after main section
// and do not prevent SW to install. Change to `optional` if
// do not want them to be preloaded at all (cached only when first loaded)
additional: ['*.chunk.js'],
},
// Removes warning for about `additional` section usage
safeToUseOptionalCaches: true,
autoUpdate: true,
}),
new WebpackPwaManifest({
name: 'my_app_name',
short_name: 'my_app_short_name',
description: 'my_app_description',
background_color: '#364150',
theme_color: '#b1624d',
icons: [
{
src: path.resolve('app/images/icon-512x512.png'),
sizes: [72, 96, 120, 128, 144, 152, 167, 180, 192, 384, 512],
},
],
}),
所以服务人员可以工作,我可以在 chrome devtools 上看到它。 pwa 被 chrome 识别,当我导航到我的 url(由 https 中的 heroku 托管)时,chrome 会提示在移动设备上提供安装建议。 然后我将应用程序安装到我的安卓手机上,登录并像往常一样使用它。当我离线时一切仍然有效,我可以浏览我的应用程序,我可以最小化它并重新打开,到目前为止一切都很好。 当我关闭我的应用程序(使用任务管理器)时,我会离线,然后打开它会提示白页或无连接提示。 有小费吗? 在成瘾中,它实际上是如何工作的?每次我单击已安装的 pwa 时,它都会检查我是否有连接并下载(如果存在)较新版本的应用程序?
【问题讨论】:
标签: android webpack service service-worker progressive-web-apps