sw-precache-webpack-plugin: Wrong path to assets when built on windows

image

Any configuration I’m missing, or is there a bug? It’s working fine when building on my mac, but our build server is running TeamCity/Windows.

My config:

new SWPrecacheWebpackPlugin({
  cacheId: 'sw-precache-pwa',
  filename: 'sw-precache.js',
})

Isn’t https://github.com/goldhand/sw-precache-webpack-plugin/blob/master/src/index.js#L66 this supposed to strip away this?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I encountered the same problem and got around it by adding stripPrefix. Due to windows I had to replace the slashes with forwardslashes in the path to get it working.

My sw-precache-config:

const SW_PRECACHE_CONFIG = {
  cacheId: SERVICE_WORKER_CACHEID,
  filename: SERVICE_WORKER_FILENAME,
  stripPrefix: path.join(__dirname, 'dist').replace(/\\/g,"/")
};

sw-precache-webpack-plugin also automatically sets stripPrefix to webpack’s outputPath and is influenced by the publicPath as well

  if (outputPath) {
          // strip the webpack config's output.path
          config.stripPrefix = outputPath + '/';
        }

        if (compiler.options.output.publicPath) {
          // prepend the public path to the resources
          config.replacePrefix = compiler.options.output.publicPath;
        }