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

时间:2017-05-11 03:33:14

标签: polymer polymer-1.0 polymer-starter-kit polymer-2.x

我无法确定为什么离线首先不在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'
        }
      }
    }
  ]
};

polymer.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}
  }]
}

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

1 个答案:

答案 0 :(得分:0)

您必须向要包括服务工作者的每个"swPrecacheConfig": "sw-precache-config.js",数组项添加'build'。 另外,请注意,开发(polymer serve)环境(未构建)会绕过服务人员注册。