How to use the workbox-build.generateSWString 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 lavas-project / lavas / packages / tb-lavas-core / core / plugins / workbox-webpack-plugin / generate-sw.js View on Github external
compilation.assets[manifestFilename] = manifestAsset;
    this.config.importScripts.push(
      (compilation.options.output.publicPath || '') + manifestFilename);

    // workboxSWImports might be null if importWorkboxFrom is 'disabled'.
    if (workboxSWImports) {
      // workboxSWImport is an array, so use concat() rather than push().
      this.config.importScripts = this.config.importScripts.concat(
        workboxSWImports);
    }

    const sanitizedConfig = sanitizeConfig.forGenerateSWString(this.config);
    // If globPatterns isn't explicitly set, then default to [], instead of
    // the workbox-build.generateSWString() default.
    sanitizedConfig.globPatterns = sanitizedConfig.globPatterns || [];
    const serviceWorker = await generateSWString(sanitizedConfig);
    compilation.assets[this.config.swDest] =
      convertStringToAsset(serviceWorker);
  }
github lavas-project / lavas / packages / lavas-core-vue / core / plugins / workbox-webpack-plugin / generate-sw.js View on Github external
const manifestFilename = `precache-manifest.${manifestHash}.js`;
    compilation.assets[manifestFilename] = manifestAsset;
    this.config.importScripts.push(manifestFilename);

    // workboxSWImports might be null if importWorkboxFrom is 'disabled'.
    if (workboxSWImports) {
      // workboxSWImport is an array, so use concat() rather than push().
      this.config.importScripts = this.config.importScripts.concat(
        workboxSWImports);
    }

    const sanitizedConfig = sanitizeConfig.forGenerateSWString(this.config);
    // If globPatterns isn't explicitly set, then default to [], instead of
    // the workbox-build.generateSWString() default.
    sanitizedConfig.globPatterns = sanitizedConfig.globPatterns || [];
    const serviceWorker = await generateSWString(sanitizedConfig);
    compilation.assets[this.config.swDest] =
      convertStringToAsset(serviceWorker);
  }
github ragingwind / next-workbox-webpack-plugin / index.js View on Github external
async generateSW(swDest, swConfig) {
    const { swString } = await generateSWString(swConfig);
    fs.writeFileSync(swDest, swString);
  }

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 24 days ago

Package Health Score

91 / 100
Full package analysis