为什么离线首先在聚合物中不起作用2



我无法说服为什么离线首先在 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}
  }]
}

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

您必须向要包含服务辅助角色的每个'build'数组项添加"swPrecacheConfig": "sw-precache-config.js",。另请注意,dev ( polymer serve ( 环境(未构建(会绕过服务工作进程注册。

最新更新