stripPrefix not stripped, but added
Closed this issue · 3 comments
Hi there,
I'm using this plugin to cache some static files. I try doing this by adding the code below. The issue is in the array of staticFileGlobs
.
new SWPrecacheWebpackPlugin({
cacheId: 'prod1',
filepath: `${PATHS.build}/sw.js`,
maximumFileSizeToCacheInBytes: 4194304,
staticFileGlobs: [`${PATHS.assets}/*.{png,jpg,gif,svg}`, `${PATHS.publicDir}/fonts/*.{ttf,woff}`],
stripPrefix: '/Users/username/Developer/React/website.com/public/'
}),
The images with PATHS.assets
are correctly inserted in my service worker. This is my main webpack output path. But the fonts in PATHS.publicDir
are inserted into the service worker with the absolute path of my computer. I did try to strip this text by adding it to the stripPrefix
, but it seems that this doesn't work as expected.
Any heads up?
I'm assuming you're running on Windows? From what I can tell, this wouldn't be an issue on Linux or Mac.
I just had this issue myself, but I think I've got it figured out. The slashes in the path don't match ("/" vs ""), so the text doesn't get replaced. If you look in the generated service worker, the paths use "/", but the path used in the webpack config uses "". I got it to strip properly by doing "stripPrefix: webRoot.replace(/\/g, "/")" in my plugin options.
I'm running on macOS. But my generated service worker looks like:
[["/Users/username/Developer/React/website.com/public/assets/Font.woff","ce77b69c5e5e1b26425e0600a73d96fe"], ["/assets/8e424b1c62c9e3f117703c68ed1aaf46.svg","8e424b1c62c9e3f117703c68ed1aaf46"],["/assets/bg.png","8d15b382c015dd1b4f14b10d73cd86f4"]["/assets/motor.png","a2711c0f65514067838154529f78a098"]];
etc..
hmmm.... Have you tried removing the last / after "public"? I tried leaving something like that in to make the paths relative, and it stopped working.