How to use the workbox-build.generateSW function in workbox-build

To help you get started, we’ve selected a few workbox-build examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marcusasplund / sweref-convert / taskfile.js View on Github external
export async function cache () {
  await wbBuild.generateSW({
    cacheId: `${applicationId}`,
    globDirectory: `${releaseTarget}/`,
    swDest: `${releaseTarget}/sw.js`,
    globPatterns: ['*.{html,css,js}']
  })
    .then(() => {
      console.log('Service worker generated.')
    })
    .catch((err) => {
      console.log('[ERROR] This happened: ' + err)
    })
}
github onedevstudio / starter-kit / gulpfile.js View on Github external
task('generate-service-worker', () =>
  wbBuild.generateSW({
    globDirectory: config.dest.dist,
    swDest: `${config.dest.dist}/sw.js`,
    globPatterns: ['**\/*.{html,js,css}']
  })
    .then(() => {
      console.log('Service worker generated.')
    })
    .catch((err) => {
      console.log('[ERROR] This happened: ' + err)
    }))
github jimpick / dat-shopping-list / server / makeServiceWorker.js View on Github external
function makeServiceWorker (cb) {
  console.log('Making service worker')
  workboxBuild
    .generateSW({
      swDest: '.data/sw.js',
      importWorkboxFrom: 'local',
      skipWaiting: true,
      clientsClaim: true,
      navigateFallback: '/',
      navigateFallbackWhitelist: [/^\/doc/, /^\/create/, /^\/add-link/],
      globDirectory: '.',
      globPatterns: ['index.html', 'static/manifest.webmanifest', 'static/**/*.svg', '.data/**/*.png'],
      modifyUrlPrefix: {
        'static': '',
        '.data': ''
      },
      templatedUrls: {
        '/': [ 'views/main.js' ]
      },
github mazipan / workbox-in-js-framework / workbox-in-react / using-workbox-build / generate-sw / my-project / src / sw-build.js View on Github external
const { generateSW } = require('workbox-build');

  const swDest = 'build/sw.js';
  generateSW({
    swDest,
    globDirectory: 'build'
  }).then(({count, size}) => {
    console.log(`Generated ${swDest}, which will precache ${count} files, totaling ${size} bytes.`);
  });
github nuxt-community / modules / modules / workbox / index.js View on Github external
builder.plugin('built', () => {
      if (workboxOptions.swSrc) {
        return swBuild.injectManifest(workboxOptions)
      } else {
        return swBuild.generateSW(workboxOptions)
      }
    })
  })
github chialab / rna-cli / commands / sw / action.js View on Github external
tmpFile.write(fs.readFileSync(output, 'utf8').replace(/\.(precache|precacheAndRoute)\s*\(\s*\[([^\]]*)\]\)/gi, '.$1([])'));
            try {
                res = await workbox.injectManifest({
                    swSrc: tmpFile.path,
                    swDest: output,
                    globDirectory: input,
                    globPatterns: ['**/*'],
                    globIgnores: exclude,
                    maximumFileSizeToCacheInBytes: 1024 * 1024 * 10,
                });
            } catch (err) {
                tmpFile.unlink();
                throw err;
            }
        } else {
            res = await workbox.generateSW({
                globDirectory: input,
                swDest: output,
                globPatterns: ['**/*'],
                globIgnores: exclude,
                maximumFileSizeToCacheInBytes: 1024 * 1024 * 10,
            });
        }

        task();
        app.log(colors.bold(colors.green('service worker generated!')));
        let { size, zipped } = utils.size(options.output);
        app.log(`${utils.relativeToCwd(options.output)} ${colors.grey(`(${utils.prettyBytes(size)}, ${utils.prettyBytes(zipped)} zipped)`)}`);
        if (options.watch) {
            let watcher = new Watcher(input, {
                log: false,
                ignore: '**/*.map',
github GoogleChrome / workbox / packages / workbox-webpack-plugin / index.js View on Github external
compiler.plugin('after-emit', (compilation, callback) => {
      const config = this.getConfig(compilation);
      if (config.swSrc) {
        swBuild.injectManifest(config)
          .then(() => callback())
          .catch((e) => callback(e));
      } else {
        swBuild.generateSW(config)
        .then(() => callback())
        .catch((e) => callback(e));
      }
    });
  }
github chrisdmacrae / parceleventy / lib / parcel / parcel-plugin-service-worker / lib / ServiceWorker.js View on Github external
const defaultConfig = {
                globDirectory: this.options.outDir,
                globPatterns: [
                '**/*.{js,css,html,png,jpg,jpeg,gif,tiff}'
                ],
                importWorkboxFrom: 'disabled',
                importScripts: [],
                swDest: destination
            }
            const cfg = Object.assign(defaultConfig, config);

            cfg.importScripts = cfg.importScripts.concat(this.importScripts);

            logger.progress('Creating service worker...');

            await workbox.generateSW(cfg);

            logger.log('Service worker generated at: ' + cfg.swDest);
        } catch (error) {
            throw error;
        }
    }
github openstax / os-webview / gulp / tasks / service-worker.js View on Github external
function precache() {
    return workboxBuild.generateSW(path.join(config.dest, 'sw.js'), {
        staticFileGlobs: shellFiles.map((uri) => `${config.dest}${uri}`),
        stripPrefix: config.dest,
        navigateFallback: '/404',
        cacheId: packageName
    });
}

workbox-build

A module that integrates into your build process, helping you generate a manifest of local files that workbox-sw should precache.

MIT
Latest version published 2 months ago

Package Health Score

91 / 100
Full package analysis