sw-precache-webpack-plugin icon indicating copy to clipboard operation
sw-precache-webpack-plugin copied to clipboard

How to strip prefix from just *.html files?

Open phun-ky opened this issue 7 years ago • 2 comments

BEFORE YOU SUBMIT please read the following:

  • [x] I'm submitting a support request

webpack version: ^3.5.5

sw-precache-webpack-plugin version: ^0.11.4

Please tell us about your environment: Windows 10 with Ubuntu Bash

Current behavior: index.html is added to sw with /assets/-prefix

Expected/desired behavior: index.html is added to sw with no prefix

  • Webpack configuration:
new SWPrecacheWebpackPlugin({
  cacheId: '<id>',
  filename: 'serviceworker.js',
  minify: false,
  maximumFileSizeToCacheInBytes: 3500000,
  filepath: path.join(assetsDir, '/serviceworker.js'),
  mergeStaticsConfig: true,
  staticFileGlobsIgnorePatterns: [/serviceworker\.js$/i],
  // This obviously does not work :/
  stripPrefixMulti: {
    '/assets/index.html': 'index.html'
  },
  navigateFallback: '/index.html'
})
  • Generated service worker (not minified): Irrelevant files ommitted https://gist.github.com/phun-ky/c66786d9a91604baf308dbb7ebd4ed6a

I'm trying to cache the html files, but with the current setup, the html files is cached with the /assets/-prefix, resulting in no offline support(?) and no caching of the files. How can I achieve what I want to do?

phun-ky avatar Feb 15 '18 13:02 phun-ky

Related to https://github.com/goldhand/sw-precache-webpack-plugin/issues/79 I think

phun-ky avatar Feb 15 '18 13:02 phun-ky

With this config:

new SWPrecacheWebpackPlugin({
  cacheId: '<id>',
  filename: '<id>-sw.js',
  minify: false,
  maximumFileSizeToCacheInBytes: 3500000,
  filepath: path.join(assetsDir, '/<id>-sw.js'),
  staticFileGlobs: ['dist/assets/index.html', 'dist/assets/down.html'],
  mergeStaticsConfig: true,
  staticFileGlobsIgnorePatterns: [/<id>-sw\.js$/i],
  stripPrefix: 'dist/assets/',
  navigateFallback: '/index.html'
})

I get:

var precacheConfig = [
  ["/assets/down.html", "0561d4adc94e9ea44ad880dceba708dc"],
  ["/assets/index.html", "400b443ac89eb1a134c9cace50be9edc"],
  ["down.html", "0561d4adc94e9ea44ad880dceba708dc"],
  ["index.html", "400b443ac89eb1a134c9cace50be9edc"]
];

Which is working! How do I get rid of the assets/*.html-entries?

phun-ky avatar Feb 15 '18 13:02 phun-ky