How to use the workbox-build.getModuleUrl 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 GoogleChrome / workbox / packages / workbox-webpack-plugin / src / lib / get-workbox-sw-imports.js View on Github external
async function getWorkboxSWImport(compilation, config) {
  switch (config.importWorkboxFrom) {
    case 'cdn': {
      return [getModuleUrl('workbox-sw')];
    }

    case 'local': {
    // This will create a local copy of the Workbox runtime libraries in
    // the output directory, independent of the webpack build pipeline.
    // In general, this should work, but one thing to keep in mind is that
    // when using the webpack-dev-server, the output will be created on
    // disk, rather than in the in-memory filesystem. (webpack-dev-server will
    // still be able to serve the runtime libraries from disk.)
      const wbDir = await copyWorkboxLibraries(path.join(
          compilation.options.output.path, config.importsDirectory));

      // We need to set this extra option in the config to ensure that the
      // workbox library loader knows where to get the local libraries from.
      config.modulePathPrefix = (compilation.options.output.publicPath || '') +
        path.join(config.importsDirectory, wbDir).split(path.sep).join('/');
github lavas-project / lavas / packages / tb-lavas-core / core / plugins / workbox-webpack-plugin / lib / get-workbox-sw-imports.js View on Github external
async function getWorkboxSWImport(compilation, config) {
  switch (config.importWorkboxFrom) {
    case 'cdn': {
      return [getModuleUrl('workbox-sw')];
    }

    case 'local': {
      // This will create a local copy of the Workbox runtime libraries in
      // the output directory, independent of the webpack build pipeline.
      // In general, this should work, but one thing to keep in mind is that
      // when using the webpack-dev-server, the output will be created on
      // disk, rather than in the in-memory filesystem. (webpack-dev-server will
      // still be able to serve the runtime libraries from disk.)
      const wbDir = await copyWorkboxLibraries(compilation.options.output.path);
      const workboxSWImport = (compilation.options.output.publicPath || '')
        + wbDir + '/workbox-sw.js';
      // We need to set this extra option in the config to ensure that the
      // workbox library loader knows where to get the local libraries from.
      config.modulePathPrefix = wbDir;
      return [workboxSWImport];
github lavas-project / lavas / packages / lavas-core-vue / core / plugins / workbox-webpack-plugin / lib / get-workbox-sw-imports.js View on Github external
function getWorkboxSWImport(compilation, config) {
  switch (config.importWorkboxFrom) {
    case 'cdn': {
      return [getModuleUrl('workbox-sw')];
    }

    case 'local': {
      // TODO: Implement.
      throw Error(`importWorkboxFrom 'local' is not yet supported.`);
    }

    case 'disabled': {
      return null;
    }

    default: {
      // If importWorkboxFrom is anything else, then treat it as the name of
      // a webpack chunk that corresponds to the custom compilation of the
      // Workbox code.
      for (const chunk of compilation.chunks) {

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

Package Health Score

91 / 100
Full package analysis