Tools: Build adds leading slashes to relative paths to resources defined in sw-precache-config.js

Created on 15 Jun 2016  路  3Comments  路  Source: Polymer/tools

I'm deploying to Github pages which means I'm not able to deploy to the root of the server. It seems that the templates and build scripts assume that apps will deployed in the root. I sent a PR for app-drawer-template (https://github.com/Polymer/app-drawer-template/pull/22), but even with those changes in place I was having issues getting the service worker to pre-cache resources.

Even though I removed the leading slashes from paths in sw-precache-config.js, the generated service-worker.js has them added back. I had to go in and modifiy the service worker in the build directory before deploying to get things working as expected.

Build cli Medium Accepted Enhancement wontfix

Most helpful comment

For the moment I'va found a workaround to make that path relative. In the sw-precache-config.js I add:

  stripPrefix: '',
  replacePrefix:  '.',

And it adds a . before the slash.

Here my complete sw-precache-config.js file:

module.exports = {
  staticFileGlobs: [
    '/index.html',
    '/manifest.json',
    '/bower_components/webcomponentsjs/webcomponents-lite.min.js'
  ],
  stripPrefix: '',
  replacePrefix:  '.',
  navigateFallback: 'index.html',
  navigateFallbackWhitelist: [/^(?!.*\.html$|\/data\/).*/]
};

All 3 comments

We are currently working on a project to make build more customizable. I believe this functionality will be added through that interface once it is built.

pinging @justinfagnani to make sure he's aware of this.

For the moment I'va found a workaround to make that path relative. In the sw-precache-config.js I add:

  stripPrefix: '',
  replacePrefix:  '.',

And it adds a . before the slash.

Here my complete sw-precache-config.js file:

module.exports = {
  staticFileGlobs: [
    '/index.html',
    '/manifest.json',
    '/bower_components/webcomponentsjs/webcomponents-lite.min.js'
  ],
  stripPrefix: '',
  replacePrefix:  '.',
  navigateFallback: 'index.html',
  navigateFallbackWhitelist: [/^(?!.*\.html$|\/data\/).*/]
};

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidmaxwaterman picture davidmaxwaterman  路  4Comments

stramel picture stramel  路  4Comments

rwatts3 picture rwatts3  路  3Comments

priyabrat1801 picture priyabrat1801  路  3Comments

web-padawan picture web-padawan  路  4Comments