goldhand/sw-precache-webpack-plugin

index.html file generated via html-webpack-plugin resolves to filesystem path instead of relative webpack in generated service worker.

skullet opened this issue · 1 comments

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:
2.x

sw-precache-webpack-plugin version:
0.9.x

Please tell us about your environment:
Windows 10

Browser: Chrome 64

Current behavior:
Using html-webpack-plugin to generate index.html file from a template. The index.html reference in the service-worker.js preCache includes a full filesystem path for index.html. This breaks the service-worker as it can't resolve/fetch the resource using the file system path. Stripprefix unfortunately will not help us fix this as the path will vary depending on the system building the bundle. We are setting the filepath in html-webpack-plugin with filename: '../index.html'

Expected/desired behavior:
The generated sw.js should not output a full system path instead of a web relative file 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:
    Getting cleared to share this with you
  • Generated service worker (not minified):
    Getting cleared to share this with you

Closing this, I was able to fix this by creating the path to wwwroot and adding that to stripPrefixMulti, then setting mergeStaticsConfig to true.

const WEB_ROOT = path.resolve(__dirname, 'wwwroot/');
let stripPrefixMulti = {};
stripPrefixMulti[WEB_ROOT.replace(/\/g, '/')] = "";