How to use the workbox-build.injectManifest 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 eshengsky / iBlog2 / gulpfile.js View on Github external
gulp.task('service-worker', () => {
    return workboxBuild.injectManifest({
        swSrc: path.join(__dirname, './public/src/js/sw.js'),
        swDest: path.join(__dirname, './sw.js'),
        globDirectory: path.join(__dirname, './'),

        // 注意:这里有个坑!后缀{js,css,xxx} 逗号之间不能加空格,否则识别有问题!!!
        globPatterns: [
            'public/**/*.{js,css,html,png,jpg,svg,ico,swf}',
            // 'node_modules/bootstrap/**/*.min.{js,css}',
            // 'node_modules/@fortawesome/**/*.{min.css,eot,ttf,woff,woff2}',
            // 'node_modules/blueimp-file-upload/**/*.{js,css}',
            // 'node_modules/sweetalert/dist/**/*.{js,css}',
            // 'node_modules/jquery/dist/**/*.{js,css}',
            // 'node_modules/metismenu/dist/**/*.{js,css}',
            // 'node_modules/lodash/**/*.min.js',
            // 'node_modules/fuelux/dist/**/*.{js,css}',
            // 'node_modules/simplemde/dist/**/*.{js,css}',
github google-developer-training / pwa-ecommerce-demo / solution / gulpfile.babel.js View on Github external
function buildSw() {
  return workboxBuild.injectManifest({
    swSrc: 'app/sw.js',
    swDest: 'dist/sw.js',
    globDirectory: 'dist',
    globPatterns: [
      'index.html',
      'scripts/main.min.js',
      'styles/main.css',
      'images/*',
      'images/touch/*'
    ]
  }).catch(err => {
    console.log('Uh oh 😬', err);
  });
}
github mazipan / workbox-in-js-framework / workbox-in-angular / inject-manifest / my-project / sw-build.js View on Github external
const { injectManifest } = require('workbox-build');

const swSrc = './sw-template.js';
const swDest = 'dist/sw.js';
injectManifest({
  swSrc,
  swDest,
  globDirectory: 'dist'
}).then(({count, size}) => {
  console.log(`Generated ${swDest}, which will precache ${count} files, totaling ${size} bytes.`);
});
github twbs / bootstrap / build / workbox.js View on Github external
const workboxSWDestMapPath = `${workboxSWDestPath}.map`

fs.createReadStream(workboxSWSrcPath).pipe(fs.createWriteStream(workboxSWDestPath))
fs.createReadStream(workboxSWSrcMapPath).pipe(fs.createWriteStream(workboxSWDestMapPath))

const updateUrl = (manifestEntries) => manifestEntries.map((entry) => {
  if (entry.url.startsWith(buildPrefix)) {
    const regex = new RegExp(buildPrefix, 'g')
    entry.url = entry.url.replace(regex, '')
  }
  return entry
})

config.manifestTransforms = [updateUrl]

swBuild.injectManifest(config).then(() => {
  const wbSwRegex = /{fileName}/g
  fs.readFile(config.swDest, 'utf8', (err, data) => {
    if (err) {
      throw err
    }
    const swFileContents = data.replace(wbSwRegex, wbFileName)
    fs.writeFile(config.swDest, swFileContents, () => {
      console.log('Pre-cache Manifest generated.')
    })
  })
})
github PaulKinlan / topicdeck / tools / generatemanifest.js View on Github external
const swBuild = require('workbox-build');
const patterns = ['assets/templates/*.html',
  'assets/templates/*.json',
  'scripts/client.js',
  'styles/main.css'];
const config = {
  globDirectory: './dist/server/public/',
  globPatterns: patterns,
  swSrc: './dist/server/public/sw.src.js',
  swDest: './dist/server/public/sw.js',
  injectionPointRegexp: /(\[)insertfileshere(\])/,
  modifyUrlPrefix: {'': '/'}
};

swBuild.injectManifest(config).then((data) => {
  console.log(data);
  console.log('Build Manifest generated.');
});
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 davideast / hnpwa-firebase / build / sw.build.js View on Github external
function buildSW(matchers) {
  return workbox.injectManifest({
    globDirectory: './src',
    globPatterns: ['**\/*.{html,js,css,png,jpg,json}'],
    globIgnores: ['sw.main.js','404.html', 'images/icons/**/*', 'index.html'],
    swSrc: './build/sw.main.js',
    swDest: './public/sw.main.js',
  });
}
github chrisdmacrae / parceleventy / lib / parcel / parcel-plugin-service-worker / lib / ServiceWorker.js View on Github external
try {
            const defaultConfig = {
                globDirectory: this.options.outDir,
                globPatterns: [
                '**/*.{js,css,html,png,jpg,jpeg,gif,tiff}'
                ],
                swSrc: destination + ".tmp",
                swDest: destination
            }
            const cfg = Object.assign(defaultConfig, config);

            logger.progress('Injecting service worker manifest...');

            fs.copySync(cfg.swDest, cfg.swDest + ".tmp");

            let { count, size } = await workbox.injectManifest(cfg);
            fs.unlinkSync(cfg.swDest + ".tmp");

            logger.log('Service worker manifest injected at: ' + cfg.swDest);
            logger.log(`Will precache ${count} files, totaling ${size} bytes.`);
        } catch (error) {
            throw error;
        }
    }
github nuxt-community / pwa-module / packages / workbox / index.js View on Github external
const hook = () => {
    const opts = pick(options, [
      'swDest', 'swSrc', 'globDirectory', 'globFollow', 'globIgnores', 'globPatterns', 'dontCacheBustUrlsMatching',
      'globStrict', 'templatedUrls', 'maximumFileSizeToCacheInBytes', 'modifyUrlPrefix', 'manifestTransforms'
    ])
    return swBuild.injectManifest(opts)
  }

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