Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

system path in generated service-worker.js #159

Open
1 of 3 tasks
guzhongren opened this issue Oct 16, 2018 · 0 comments
Open
1 of 3 tasks

system path in generated service-worker.js #159

guzhongren opened this issue Oct 16, 2018 · 0 comments

Comments

@guzhongren
Copy link

BEFORE YOU SUBMIT please read the following:

  • I'm submitting a bug report
  • I'm submitting a feature request
  • I'm submitting a support request

webpack version:
4.20

sw-precache-webpack-plugin version:
latest

Please tell us about your environment:
Linux

Browser: [Phantom XX | Chrome XX | Firefox XX | IE XX | Safari XX | Other XX]
Chrome 64
Current behavior:
just like #142, my index.html is generated by html-webpack-plugin, my config.js is copied from local with copy-webpack-plugin; in generated file service-worker.js, like this
image

Expected/desired behavior:
let system path to relative path

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with your:

  • Webpack configuration:
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
...
new SWPrecacheWebpackPlugin({
      dontCacheBustUrlsMatching: /\.\w{8}\./,
      filename: 'service-worker.js',
      minify: true,
      mergeStaticsConfig: true,
      navigateFallback: '/dist/' + '/index.html',
      navigateFallbackWhitelist: [/^(?!\/__).*/],
      staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
      // stripPrefix: path.join(__dirname, 'dist').replace(/[a-zA-Z0-9/\\]+build/g, '/dist') // i added ,but no useful
    })
  • Generated service worker (not minified):
"use strict";
var precacheConfig = [
    ["/dist/favicon.ico", "b5f4be6421ade8fc5bdcde1839afd32f"],
    ["/dist/fonts/1b35b5.woff", "1b35b521c0082d56b9ac413ddb0660ef"],
    ["/dist/fonts/4c40e9.ttf", "4c40e950d3719c21f75c2dc7a9312999"],
    ["/dist/fonts/62759b.eot", "62759b1cf27452e085eddbb8ab29ad2b"],
    ["/dist/fonts/8c9b05.eot", "8c9b05a6db51b83bbeb48a623489b2aa"],
    ["/dist/fonts/92acc6.ttf", "92acc6829cf612e62ecf2be54e9344f0"],
    ["/dist/fonts/f2fa34.woff", "f2fa34de139501e77481e947df04d891"],
    ["/dist/images/0051dd.png", "0051ddcf95941a0b5f8c9a3eb3e48f0e"],
    ["/dist/images/0c9d50.png", "0c9d509f3692cee55f728e1eb0bf5b83"],
    ["/dist/images/18f564.png", "18f564d05b17f6efc2d8783fc9241dfb"],
    ["/dist/images/1f7759.png", "1f7759764abeebbff24b00dcca35251b"],
    ["/dist/images/22ffa1.png", "22ffa1b3964afadd3f8f4cd1b39d9a02"],
    ["/dist/images/2adfe0.png", "2adfe0592c9854f92481120aed147bb8"],
    ["/dist/images/358fcb.png", "358fcb5b8cd5b2abf451fc36e0480e74"],
    ["/dist/images/393284.png", "39328431e63485068a519576cc190b6a"],
    ["/dist/images/3a19da.png", "3a19da4f237c792e5bde0ae7ff828970"],
    ["/dist/images/5552b9.png", "5552b9bbe9e7575fae5556292281ff7e"],
    ["/dist/images/5c3668.png", "5c3668b5fb1416b591e82d8100a60294"],
    ["/dist/images/657910.png", "657910a808ed7e42fcc4327f04c586b8"],
    ["/dist/images/6e3e89.png", "6e3e890d649dd3798e4d2310253c494d"],
    ["/dist/images/7404d1.png", "7404d12c8d2e65ffbc65926e98866e50"],
    ["/dist/images/7aa486.png", "7aa4861c6f7469881d32ea86808e9081"],
    ["/dist/images/814a8a.png", "814a8a59415c9e920ea3ef136d24f0f3"],
    ["/dist/images/90097b.png", "90097b974a2ea36a8be7ea8ed0b83baa"],
    ["/dist/images/a009f7.png", "a009f7f796cff0dfdb8eb5aa135b4cae"],
    ["/dist/images/bda41e.png", "bda41e42b7b63b5d2fea8c78ddf8be24"],
    ["/dist/images/ca5d45.svg", "ca5d4588dad9c32f49e895e7f19479df"],
    ["/dist/images/ea721a.png", "ea721a1a01fdeb5dcbc766676e83a72c"],
    ["/dist/images/edeeff.png", "edeeff60e7a0404a9fc40253c4c0240f"],
    ["/dist/images/ee54be.png", "ee54be898531a91a958840a809f75131"],
    ["/dist/images/f2881f.png", "f2881f99ea4c3a292a1c5e36642cd062"],
    ["/dist/images/f3cad8.png", "f3cad8416e24a89a9f94aed78b2dec8c"],
    ["/dist/js/2_bundle.js", "6acbaad121e56938a65db7b77641d0d8"],
    ["/dist/js/3_bundle.js", "062674176ae97b14a1b4043f2988c95c"],
    ["/dist/js/4_bundle.js", "b782bb05914cb524a99e5c731d790187"],
    ["/dist/js/app_bundle.js", "d94779c11322e9a7ff12ebece77e741b"],
    ["/dist/js/runtime_bundle.js", "2b836ad06df9998d358346bf35d76e6d"],
    ["/dist/style/2.css", "53ac223df2aea7dec705012ec556daae"],
    ["/dist/style/3.css", "f9fa71513a18887291fafde6c89f38df"],
    ["/dist/style/4.css", "566bec76673f96860938dc6c4558d01a"],
    ["/dist/style/app.css", "f82983901e4266328c1af75d12ae1d88"],
    ["/dist/style/vendors.css", "dc3df81b3bb041761595338061eb28aa"],
    ["/home/c4/Desktop/Project/SummitWeb/build/config.js", "b0ebcf61d580987a8b3b075bd6aeff6a"],
    ["/home/c4/Desktop/Project/SummitWeb/build/index.html", "ffb440e6c16a845e9d017141cfd96970"]
  ],
  cacheName = "sw-precache-v3-sw-precache-webpack-plugin-" + (self.registration ? self.registration.scope : ""),
  ignoreUrlParametersMatching = [/^utm_/],
  addDirectoryIndex = function (e, a) {
    var t = new URL(e);
    return "/" === t.pathname.slice(-1) && (t.pathname += a), t.toString()
  },
  cleanResponse = function (e) {
    return e.redirected ? ("body" in e ? Promise.resolve(e.body) : e.blob()).then(function (a) {
      return new Response(a, {
        headers: e.headers,
        status: e.status,
        statusText: e.statusText
      })
    }) : Promise.resolve(e)
  },
  createCacheKey = function (e, a, t, s) {
    var n = new URL(e);
    return s && n.pathname.match(s) || (n.search += (n.search ? "&" : "") + encodeURIComponent(a) + "=" + encodeURIComponent(t)), n.toString()
  },
  isPathWhitelisted = function (e, a) {
    if (0 === e.length) return !0;
    var t = new URL(a).pathname;
    return e.some(function (e) {
      return t.match(e)
    })
  },
  stripIgnoredUrlParameters = function (e, a) {
    var t = new URL(e);
    return t.hash = "", t.search = t.search.slice(1).split("&").map(function (e) {
      return e.split("=")
    }).filter(function (e) {
      return a.every(function (a) {
        return !a.test(e[0])
      })
    }).map(function (e) {
      return e.join("=")
    }).join("&"), t.toString()
  },
  hashParamName = "_sw-precache",
  urlsToCacheKeys = new Map(precacheConfig.map(function (e) {
    var a = e[0],
      t = e[1],
      s = new URL(a, self.location),
      n = createCacheKey(s, hashParamName, t, /\.\w{8}\./);
    return [s.toString(), n]
  }));

function setOfCachedUrls(e) {
  return e.keys().then(function (e) {
    return e.map(function (e) {
      return e.url
    })
  }).then(function (e) {
    return new Set(e)
  })
}
self.addEventListener("install", function (e) {
  e.waitUntil(caches.open(cacheName).then(function (e) {
    return setOfCachedUrls(e).then(function (a) {
      return Promise.all(Array.from(urlsToCacheKeys.values()).map(function (t) {
        if (!a.has(t)) {
          var s = new Request(t, {
            credentials: "same-origin"
          });
          return fetch(s).then(function (a) {
            if (!a.ok) throw new Error("Request for " + t + " returned a response with status " + a.status);
            return cleanResponse(a).then(function (a) {
              return e.put(t, a)
            })
          })
        }
      }))
    })
  }).then(function () {
    return self.skipWaiting()
  }))
}), self.addEventListener("activate", function (e) {
  var a = new Set(urlsToCacheKeys.values());
  e.waitUntil(caches.open(cacheName).then(function (e) {
    return e.keys().then(function (t) {
      return Promise.all(t.map(function (t) {
        if (!a.has(t.url)) return e.delete(t)
      }))
    })
  }).then(function () {
    return self.clients.claim()
  }))
}), self.addEventListener("fetch", function (e) {
  if ("GET" === e.request.method) {
    var a, t = stripIgnoredUrlParameters(e.request.url, ignoreUrlParametersMatching);
    (a = urlsToCacheKeys.has(t)) || (t = addDirectoryIndex(t, "index.html"), a = urlsToCacheKeys.has(t));
    !a && "navigate" === e.request.mode && isPathWhitelisted(["^(?!\\/__).*"], e.request.url) && (t = new URL("/dist//index.html", self.location).toString(), a = urlsToCacheKeys.has(t)), a && e.respondWith(caches.open(cacheName).then(function (e) {
      return e.match(urlsToCacheKeys.get(t)).then(function (e) {
        if (e) return e;
        throw Error("The cached response that was expected is missing.")
      })
    }).catch(function (a) {
      return console.warn('Couldn\'t serve response for "%s" from cache: %O', e.request.url, a), fetch(e.request)
    }))
  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant