How to use the workbox-webpack-plugin.InjectManifest function in workbox-webpack-plugin

To help you get started, we’ve selected a few workbox-webpack-plugin 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 DefinitelyTyped / DefinitelyTyped / types / workbox-webpack-plugin / workbox-webpack-plugin-tests.ts View on Github external
const manifest = originalManifest.filter(
          (entry) => entry.url !== 'ignored.html');
        // Optionally, set warning messages.
        const warnings = ['warning'];
        return {manifest, warnings: [] };
      }
    ]
  });
}

// InjectManifest
{
  let plugin: InjectManifest;

  // No options object
  plugin = new InjectManifest();

  // Minimal options object (swSrc is required)
  plugin = new InjectManifest({
    swSrc: 'service-worker.js'
  });

  // With all of the examples
  plugin = new InjectManifest({
    swDest: 'custom-sw-name.js',
    importWorkboxFrom: 'local',
    // *Only* include assets that belong to these chunks:
    chunks: ['chunk-name-1', 'chunk-name-2'],
    // Exclude assets that belong to these chunks:
    excludeChunks: ['chunk-name-1', 'chunk-name-2'],
    // Only include HTML and JS assets when precaching:
    include: [/\.html$/, /\.js$/],
github Atyantik / pawjs / src / webpack / web.config.ts View on Github external
'window.React': 'React',
        ReactDom: 'ReactDOM',
        ReactDOM: 'ReactDOM',
        'window.ReactDOM': 'ReactDOM',
        'window.ReactDom': 'ReactDOM',
      }),
    ] : []),
    new webpack.EnvironmentPlugin({ pawConfig: JSON.stringify(pawConfig), ...process.env }),
    ...(isHot ? [] : [new MiniCssExtractPlugin({
      // Options similar to the same options in webpackOptions.output
      // both options are optional
      filename: 'css/[hash].css',
      chunkFilename: 'css/[chunkhash].css',
    })]),
    ...(pawConfig.serviceWorker ? [
      new WorkboxPlugin.InjectManifest({
        swSrc: pawExistsSync(path.join(process.env.LIB_ROOT || '', 'src', 'service-worker')),
        swDest: 'sw.js',
      }),
      new SwVariables({
        fileName: 'sw.js',
        variables: { workboxDebug: true, ...pawConfig },
        text: projectSW,
      }),
    ] : []),
    ...devPlugins,
  ],
};
github DestinyItemManager / DIM / config / webpack.js View on Github external
});
  } else {
    // env.beta and env.release
    config.plugins.push(
      new CleanWebpackPlugin({
        cleanOnceBeforeBuildPatterns: ['.awcache', 'node_modules/.cache']
      }),

      // Tell React we're in Production mode
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify('production'),
        'process.env': JSON.stringify({ NODE_ENV: 'production' })
      }),

      // Generate a service worker
      new InjectManifest({
        include: [/\.(html|js|css|woff2|json|wasm)$/, /static\/.*\.(png|gif|jpg|svg)$/],
        exclude: [
          /version\.json/,
          /extension-dist/,
          /\.map$/,
          // Ignore both the webapp manifest and the d1-manifest files
          /data\/d1\/manifests/,
          /manifest-webapp/
        ],
        swSrc: './src/service-worker.js',
        swDest: 'service-worker.js',
        importWorkboxFrom: 'local'
      })
    );

    if (process.env.PT_PROJECT_TOKEN) {
github xiaoiver / a-simple-gltf-viewer / webpack.config.js View on Github external
rendererConfig.entry = './src/renderer/renderer.tsx';
rendererConfig.target = 'electron-renderer';
rendererConfig.output.filename = 'renderer.bundle.js';
rendererConfig.plugins = [
  new HtmlWebpackPlugin({
    template: path.resolve(__dirname, './public/index.html'),
  }),
  new CopyPlugin([
    { from: srcPaths('static'), to: srcPaths('docs') },
  ])
];

if (isEnvProduction) {
  rendererConfig.plugins.push(
    // @see https://github.com/xiaoiver/sw-tools/issues/1
    new InjectManifest({
      swSrc: srcPaths('src/service-worker.js'),
      swDest: 'service-worker.js',
      exclude: [/\.png|\.DS_Store$/],
      importWorkboxFrom: 'local'
    })
  );
}

module.exports = [mainConfig, rendererConfig];
github zen0822 / vue2do / script / config / dev.webpack.conf.js View on Github external
new webpack.NoEmitOnErrorsPlugin(),
      new webpack.optimize.OccurrenceOrderPlugin(),
      new HtmlWebpackPlugin({
        filename: 'index.html',
        template,
        inject: true
      })
    ]
  })

  if (process.env.SW_ENV === 'development') {
    try {
      fs.accessSync(swPath, fs.constants.F_OK)

      devConf.plugins.push(
        new WorkboxPlugin.InjectManifest({
          swSrc: swPath,
          importWorkboxFrom: 'disabled'
        })
      )
    } catch (error) {
      console.log(`\n在应用的 dist/sw 未找到 sw.js 文件,需要先运行 npm run sw:prod 生成对应文件。\n`)
    }
  }

  return devConf
}
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / ServiceWorkerPlugin.js View on Github external
applyInjectManifest(compiler) {
        let injectManifest;
        if (this.config.injectManifestConfig) {
            injectManifest = new WorkboxPlugin.InjectManifest(
                this.config.injectManifestConfig
            );
        } else {
            injectManifest = new WorkboxPlugin.InjectManifest({
                swSrc: this.config.paths.src + '/sw.js',
                swDest: this.config.paths.dest + '/sw.js'
            });
        }
        injectManifest.apply(compiler);
    }
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / ServiceWorkerPlugin.js View on Github external
applyInjectManifest(compiler) {
        let injectManifest;
        if (this.config.injectManifestConfig) {
            injectManifest = new WorkboxPlugin.InjectManifest(
                this.config.injectManifestConfig
            );
        } else {
            injectManifest = new WorkboxPlugin.InjectManifest({
                swSrc: this.config.paths.src + '/sw.js',
                swDest: this.config.paths.dest + '/sw.js'
            });
        }
        injectManifest.apply(compiler);
    }
github prateekbh / preact-cli-workbox-plugin / inject-manifest.js View on Github external
module.exports = function(config, helpers, workboxConfig) {
  const defaultConfig = getDefaultConfig(config);
  delete defaultConfig['navigateFallback'];
  delete defaultConfig['navigateFallbackWhitelist'];
  const esmConfig = getESMDefaultConfig(config);
  delete esmConfig['navigateFallback'];
  delete esmConfig['navigateFallbackWhitelist'];
  esmConfig.swDest = defaultConfig.swDest.substring(0, defaultConfig.swDest.lastIndexOf('.js')) + '-esm.js';
  esmConfig.include.push(/(\.[\w]{5}\.esm\.js)/);
  const swGenerator = new InjectManifest(Object.assign({}, defaultConfig, workboxConfig));
  return replaceDefaultPugin(config, helpers, swGenerator);
}
github wintercounter / mhy / src / configs / webpack / root / plugins.js View on Github external
export default (plugins = []) => {
    manifest.icons.map(icon => {
        const inCwdPath = path.resolve(process.cwd(), icon.src)
        if (fs.existsSync(inCwdPath)) {
            icon.src = inCwdPath
        }
        return icon
    })

    plugins = plugins.concat(new GenerateSW())

    if (fs.existsSync(swSrc)) {
        plugins.push(new InjectManifest({ swSrc }))
    }

    return plugins.concat([
        new WebpackPwaManifestPlugin(manifest),
        new WebpackManifestPlugin({
            fileName: './manifest.webpack.json'
        }),
        new webpack.DefinePlugin({
            mhy: JSON.stringify(mhyConfig)
        })
    ])
}

workbox-webpack-plugin

A plugin for your Webpack build process, helping you generate a manifest of local files that workbox-sw should precache.

MIT
Latest version published 1 month ago

Package Health Score

91 / 100
Full package analysis