How to use the workbox-build.getManifest 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 / lavas-core-vue / core / plugins / workbox-webpack-plugin / inject-manifest.js View on Github external
async handleEmit(compilation, readFile) {
    const workboxSWImports = getWorkboxSWImports(compilation, this.config);
    let entries = getManifestEntriesFromCompilation(compilation, this.config);

    const sanitizedConfig = sanitizeConfig.forGetManifest(this.config);
    // If there are any "extra" config options remaining after we remove the
    // ones that are used natively by the plugin, then assume that they should
    // be passed on to workbox-build.getManifest() to generate extra entries.
    if (Object.keys(sanitizedConfig).length > 0) {
      // If globPatterns isn't explicitly set, then default to [], instead of
      // the workbox-build.getManifest() default.
      sanitizedConfig.globPatterns = sanitizedConfig.globPatterns || [];
      const {manifestEntries} = await getManifest(sanitizedConfig);
      entries = entries.concat(manifestEntries);
    }

    const manifestString = stringifyManifest(entries);
    const manifestAsset = convertStringToAsset(manifestString);
    const manifestHash = getAssetHash(manifestAsset);
    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);
    }
github lavas-project / lavas / packages / lavas-core-vue / core / plugins / workbox-webpack-plugin / inject-manifest.js View on Github external
` InjectManifest. Please use 'cdn' or a chunk name instead.`);
    }

    const workboxSWImports = await getWorkboxSWImports(
      compilation, this.config);
    let entries = getManifestEntriesFromCompilation(compilation, this.config);

    const sanitizedConfig = sanitizeConfig.forGetManifest(this.config);
    // If there are any "extra" config options remaining after we remove the
    // ones that are used natively by the plugin, then assume that they should
    // be passed on to workbox-build.getManifest() to generate extra entries.
    if (Object.keys(sanitizedConfig).length > 0) {
      // If globPatterns isn't explicitly set, then default to [], instead of
      // the workbox-build.getManifest() default.
      sanitizedConfig.globPatterns = sanitizedConfig.globPatterns || [];
      const {manifestEntries} = await getManifest(sanitizedConfig);
      entries = entries.concat(manifestEntries);
    }

    const manifestString = stringifyManifest(entries);
    const manifestAsset = convertStringToAsset(manifestString);
    const manifestHash = getAssetHash(manifestAsset);
    let manifestFilename = `precache-manifest.${manifestHash}.js`;
    if (this.config.manifestFilename) {
        manifestFilename = this.config.manifestFilename.replace('[manifest]', manifestFilename);
    }

    compilation.assets[manifestFilename] = manifestAsset;
    compilation.assets['static/js/' + manifestFilename] = manifestAsset;

    this.config.importScripts.push(
      (compilation.options.output.publicPath || '') + manifestFilename);
github PaulKinlan / topicdeck / tools / producemanifest.js View on Github external
let mergeGeneratedManifests = async (base, overrides) => {
  let baseFiles = await swBuild.getManifest(base);
  let overrideFiles = [];
  if(!overrides.globDirectory) overrideFiles = await swBuild.getManifest(overrides);

  let baseFileMap = new Map(baseFiles.manifestEntries.map(entry => [entry.url, entry.revision]));
  let overrideFileMap = new Map(overrideFiles.manifestEntries.map(entry => [entry.url, entry.revision]));
  let finalManifest = [];

  new Map([...baseFileMap, ...overrideFileMap]).forEach((value, key) => finalManifest.push({ url: key, revision: value}));
  return finalManifest;
};
github PaulKinlan / topicdeck / tools / producemanifest.js View on Github external
let mergeGeneratedManifests = async (base, overrides) => {
  let baseFiles = await swBuild.getManifest(base);
  let overrideFiles = [];
  if(!overrides.globDirectory) overrideFiles = await swBuild.getManifest(overrides);

  let baseFileMap = new Map(baseFiles.manifestEntries.map(entry => [entry.url, entry.revision]));
  let overrideFileMap = new Map(overrideFiles.manifestEntries.map(entry => [entry.url, entry.revision]));
  let finalManifest = [];

  new Map([...baseFileMap, ...overrideFileMap]).forEach((value, key) => finalManifest.push({ url: key, revision: value}));
  return finalManifest;
};

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

Package Health Score

89 / 100
Full package analysis