Polymer / tools

Polymer Tools Monorepo
BSD 3-Clause "New" or "Revised" License
430 stars 200 forks source link

[bug] staticFileGlobs in sw-precache-config not process in build #2207

Closed AliMD closed 5 years ago

AliMD commented 8 years ago

Description

staticFileGlobs in sw-precache-config.js not process in build and compiled service-worker.js not contain these files!

Versions & Environment

module.exports = {
  staticFileGlobs: [
    '/index.html',
    '/src/manifest.json',
    '/bower_components/webcomponentsjs/webcomponents-lite.min.js',
    '/src/images/*'
  ]
};
  1. polymer build

    Expected Results

compiled service-worker.js in PrecacheConfig array contain staticFileGlobs files or in browser app work fully offline in second visit

Actual Results

app not work offline for staticFileGlobs files and images or manifest load every time from net or fail in offline mode!

Other auto detect files and components work offline

VandeurenGlenn commented 8 years ago

Same here, PrecacheConfig contains all items defined in polymer.json butt doesn't contain the files defined in sw-precache-config.js

evtaranov commented 8 years ago

+1 and it is very critical. My bundled version does not work in Firefox and Safari anymore (

perciag commented 8 years ago

i had copy to folder build/unbundled manually, that's very bad.

veith commented 8 years ago

Do not forget to copy the files before you run polymer build. Otherwise your service-worker.js will not contain the files, because sw-precache checks if the files exists.

FredKSchott commented 8 years ago

Oh yea, jeeze look at this (output from when I run polymer build --verbose in the shop template):

{ staticFileGlobs: 
   [ 'build/bundled/build/unbundled/index.html',
     'build/bundled/build/unbundled/manifest.json',
     'build/bundled/build/unbundled/bower_components/webcomponentsjs/webcomponents-lite.min.js',
     'build/bundled/build/unbundled/images/*',
     'build/bundled/build/unbundled/src/shop-app.html',
     'build/bundled/build/unbundled/src/shop-list.html',
     'build/bundled/build/unbundled/src/shop-detail.html',
     'build/bundled/build/unbundled/src/shop-cart.html',
     'build/bundled/build/unbundled/src/shop-checkout.html',
     'build/bundled/build/unbundled/src/lazy-resources.html',
     'build/bundled/build/unbundled/index.html',
     'build/bundled/build/unbundled/bower_components/polymer/polymer.html',
     'build/bundled/build/unbundled/bower_components/polymer/polymer-mini.html',
     'build/bundled/build/unbundled/bower_components/polymer/polymer-micro.html',
     'build/bundled/build/unbundled/src/shop-button.html',
     'build/bundled/build/unbundled/src/shop-common-styles.html',
     'build/bundled/build/unbundled/bower_components/iron-flex-layout/iron-flex-layout.html',
     'build/bundled/build/unbundled/src/shop-form-styles.html',
     'build/bundled/build/unbundled/bower_components/app-route/app-route.html',
     'build/bundled/build/unbundled/src/shop-category-data.html',
     'build/bundled/build/unbundled/src/shop-image.html',
     'build/bundled/build/unbundled/src/shop-list-item.html',
     'build/bundled/build/unbundled/src/shop-select.html',
     'build/bundled/build/unbundled/src/shop-input.html',
     'build/bundled/build/unbundled/src/shop-checkbox.html',
     'build/bundled/build/unbundled/bower_components/app-layout/app-header/app-header.html',
     'build/bundled/build/unbundled/bower_components/iron-resizable-behavior/iron-resizable-behavior.html',
     'build/bundled/build/unbundled/bower_components/app-layout/app-scroll-effects/app-scroll-effects-behavior.html',
     'build/bundled/build/unbundled/bower_components/iron-scroll-target-behavior/iron-scroll-target-behavior.html',
     'build/bundled/build/unbundled/bower_components/app-layout/helpers/helpers.html',
     'build/bundled/build/unbundled/bower_components/app-layout/app-scroll-effects/effects/waterfall.html',
     'build/bundled/build/unbundled/bower_components/app-layout/app-toolbar/app-toolbar.html',
     'build/bundled/build/unbundled/bower_components/app-route/app-location.html',
     'build/bundled/build/unbundled/bower_components/iron-location/iron-location.html',
     'build/bundled/build/unbundled/bower_components/iron-location/iron-query-params.html',
     'build/bundled/build/unbundled/bower_components/app-route/app-route-converter-behavior.html',
     'build/bundled/build/unbundled/bower_components/iron-media-query/iron-media-query.html',
     'build/bundled/build/unbundled/bower_components/iron-pages/iron-pages.html',
     'build/bundled/build/unbundled/bower_components/iron-selector/iron-selectable.html',
     'build/bundled/build/unbundled/bower_components/iron-selector/iron-selection.html',
     'build/bundled/build/unbundled/bower_components/iron-selector/iron-selector.html',
     'build/bundled/build/unbundled/bower_components/iron-selector/iron-multi-selectable.html',
     'build/bundled/build/unbundled/src/shop-home.html',
     'build/bundled/build/unbundled/bower_components/app-layout/app-drawer/app-drawer.html',
     'build/bundled/build/unbundled/bower_components/paper-icon-button/paper-icon-button.html',
     'build/bundled/build/unbundled/bower_components/iron-icon/iron-icon.html',
     'build/bundled/build/unbundled/bower_components/iron-meta/iron-meta.html',
     'build/bundled/build/unbundled/bower_components/paper-behaviors/paper-inky-focus-behavior.html',
     'build/bundled/build/unbundled/bower_components/iron-behaviors/iron-button-state.html',
     'build/bundled/build/unbundled/bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html',
     'build/bundled/build/unbundled/bower_components/iron-behaviors/iron-control-state.html',
     'build/bundled/build/unbundled/bower_components/paper-behaviors/paper-ripple-behavior.html',
     'build/bundled/build/unbundled/bower_components/paper-ripple/paper-ripple.html',
     'build/bundled/build/unbundled/bower_components/paper-styles/default-theme.html',
     'build/bundled/build/unbundled/bower_components/paper-styles/color.html',
     'build/bundled/build/unbundled/src/shop-analytics.html',
     'build/bundled/build/unbundled/src/shop-cart-data.html',
     'build/bundled/build/unbundled/bower_components/iron-localstorage/iron-localstorage.html',
     'build/bundled/build/unbundled/src/shop-cart-modal.html',
     'build/bundled/build/unbundled/bower_components/iron-overlay-behavior/iron-overlay-behavior.html',
     'build/bundled/build/unbundled/bower_components/iron-fit-behavior/iron-fit-behavior.html',
     'build/bundled/build/unbundled/bower_components/iron-overlay-behavior/iron-overlay-manager.html',
     'build/bundled/build/unbundled/bower_components/iron-overlay-behavior/iron-overlay-backdrop.html',
     'build/bundled/build/unbundled/src/shop-icons.html',
     'build/bundled/build/unbundled/bower_components/iron-iconset-svg/iron-iconset-svg.html',
     'build/bundled/build/unbundled/src/shop-snackbar.html',
     'build/bundled/build/unbundled/src/shop-tabs.html',
     'build/bundled/build/unbundled/src/shop-tabs-overlay.html',
     'build/bundled/build/unbundled/src/shop-tab.html',
     'build/bundled/build/unbundled/src/shop-ripple-container.html',
     'build/bundled/build/unbundled/src/shop-network-warning.html',
     'build/bundled/build/unbundled/src/shop-cart-item.html',
     'build/bundled/build/unbundled/bower_components/iron-form/iron-form.html',
     'build/bundled/build/unbundled/bower_components/iron-ajax/iron-ajax.html',
     'build/bundled/build/unbundled/bower_components/iron-ajax/iron-request.html',
     'build/bundled/build/unbundled/bower_components/promise-polyfill/promise-polyfill-lite.html',
     'build/bundled/build/unbundled/bower_components/paper-spinner/paper-spinner-lite.html',
     'build/bundled/build/unbundled/bower_components/paper-spinner/paper-spinner-behavior.html',
     'build/bundled/build/unbundled/bower_components/paper-spinner/paper-spinner-styles.html',
     'build/bundled/build/unbundled/bower_components/promise-polyfill/Promise.js',
     'build/bundled/src/shop-app.html',
     'build/bundled/src/shop-list.html',
     'build/bundled/src/shop-detail.html',
     'build/bundled/src/shop-cart.html',
     'build/bundled/src/shop-checkout.html',
     'build/bundled/src/lazy-resources.html',
     'build/bundled/index.html',
     'build/bundled/shared-bundle.html' ],
  navigateFallback: '/index.html',
  navigateFallbackWhitelist: [ /^(?!.*\.html$|\/data\/).*/ ],
  runtimeCaching: 
   [ { urlPattern: /\/data\/images\/.*/,
       handler: 'cacheFirst',
       options: { cache: { maxEntries: 200, name: 'items-cache' } } },
     { urlPattern: /\/data\/.*json/,
       handler: 'fastest',
       options: { cache: { maxEntries: 100, name: 'data-cache' } } } ],
  stripPrefix: 'build/bundled',
  logger: [Function: bound _log],
  cacheId: '',
  directoryIndex: 'index.html',
  dynamicUrlToDependencies: {},
  handleFetch: true,
  ignoreUrlParametersMatching: [ /^utm_/ ],
  importScripts: [],
  maximumFileSizeToCacheInBytes: 2097152,
  replacePrefix: '',
  templateFilePath: '/Users/fschott/Code/polytool/node_modules/sw-precache/service-worker.tmpl',
  verbose: false }

It looks like we're running into a problem where the same swConfig object is being sent to both builds (bundled & unbundled) and then the staticFileGlobs array is shared and modified between the two. No good.

I'll try to fix this ASAP so that we can get a fix out in the next release.

FredKSchott commented 8 years ago

Thanks for reporting @AliMD & all

FredKSchott commented 8 years ago

PR to fix: https://github.com/Polymer/polymer-build/pull/27

FredKSchott commented 8 years ago

Fixed in v0.16.0 (just pushed out)

veith commented 8 years ago

Thanks a lot.

But i think this is not the expected behavior. When you make a clean build (or first build) the files from staticFileGlobs are not copied. Therefore they are not listed in service-worker.js.

@FredKSchott Please reopen this issue.