0

我无法说服为什么离线首先不能在 Polymer2 中工作。这是我的sw-precache-config.jspolymer.json

module.exports = {
  staticFileGlobs: [
    '/index.html',
    '/manifest.json',
    '/bower_components/webcomponentsjs/webcomponents-loader.js',
    '/images/*'
  ],
  navigateFallback: '/index.html',
  navigateFallbackWhitelist: [/^(?!.*\.html$|\/data\/).*/],
  runtimeCaching: [
    {
      urlPattern: /\/bower_components\/webcomponentsjs\/.*.js/,
      handler: 'fastest',
      options: {
        cache: {
          name: 'webcomponentsjs-polyfills-cache'
        }
      }
    },
    {
      urlPattern: /\/data\/images\/.*/,
      handler: 'cacheFirst',
      options: {
        cache: {
          maxEntries: 200,
          name: 'items-cache'
        }
      }
    },
    {
      urlPattern: /\/data\/.*json/,
      handler: 'fastest',
      options: {
        cache: {
          maxEntries: 100,
          name: 'data-cache'
        }
      }
    }
  ]
};

聚合物.json

{
  "entrypoint": "index.html",
  "shell": "src/my-app.html",
  "fragments": [
    "src/my-home.html",
    "src/my-category.html",
    "src/my-company.html",
    "src/my-courses.html",
    "src/my-view404.html"
  ],
  "sources": [
    "src/**/*",
    "data/**/*",
    "images/**/*",
    "bower.json"
  ],
  "extraDependencies": [
    "manifest.json",
    "bower_components/webcomponentsjs/*.js"
  ],
  "lint": {
    "rules": ["polymer-2"]
  },
  "builds": [{
    "name": "bundled",
    "addServiceWorker": true,
    "bundle": true,
    "js": {"minify": false, "compile": false},
    "css": {"minify": false},
    "html": {"minify": false}
  },{
    "name": "unbundled",
    "addServiceWorker": true,
    "bundle": false,
    "js": {"minify": true, "compile": true},
    "css": {"minify": true},
    "html": {"minify": true}
  }]
}

请让我知道为什么它根本不起作用?

4

1 回答 1

0

您必须添加到要包含服务人员的"swPrecacheConfig": "sw-precache-config.js",每个数组项。'build'另外,请注意 dev ( polymer serve) 环境(未构建)绕过 service worker 注册。

于 2018-07-19T12:20:15.607 回答