<commit_before>const appPaths = require('../../app-paths')
const PwaManifestPlugin = require('./plugin.pwa-manifest')

module.exports = function (chain, cfg) {
  // write manifest.json file
  chain.plugin('pwa-manifest')
    .use(PwaManifestPlugin, [ cfg ])

  let defaultOptions
  const WorkboxPlugin = require('workbox-webpack-plugin')
  const pluginMode = cfg.pwa.workboxPluginMode
  const log = require('../../helpers/logger')('app:workbox')

  if (pluginMode === 'GenerateSW') {
    const pkg = require(appPaths.resolve.app('package.json'))

    defaultOptions = {
      cacheId: pkg.name || 'quasar-pwa-app'
    }

    log('[GenerateSW] Will generate a service-worker file. Ignoring your custom written one.')
  }
  else {
    defaultOptions = {
      swSrc: appPaths.resolve.app(cfg.sourceFiles.serviceWorker)
    }

    log('[InjectManifest] Using your custom service-worker written file')
  }

  let opts = {
    ...defaultOptions,
    ...cfg.pwa.workboxOptions
  }

  if (cfg.ctx.mode.ssr) {
    if (pluginMode === 'GenerateSW' && !opts.directoryIndex) {
      opts.directoryIndex = cfg.build.publicPath
    }

    opts.exclude.push('../vue-ssr-client-manifest.json')

    // if Object form:
    if (cfg.ssr.pwa && cfg.ssr.pwa !== true) {
      const merge = require('webpack-merge')
      opts = merge(opts, cfg.ssr.pwa)
    }


    if (pluginMode === 'GenerateSW') {
      if (!opts.directoryIndex) {
        opts.directoryIndex = cfg.build.publicPath
      }

      if (opts.runtimeCaching.every(entry => entry.urlPattern !== cfg.build.publicPath)) {
        opts.runtimeCaching.unshift({
          urlPattern: cfg.build.publicPath,
          handler: 'StaleWhileRevalidate'
        })
      }
    }
  }

  opts.swDest = 'service-worker.js'

  chain.plugin('workbox')
    .use(WorkboxPlugin[pluginMode], [ opts ])

  if (!cfg.ctx.mode.ssr) {
    const HtmlPwaPlugin = require('./plugin.html-pwa').plugin
    chain.plugin('html-pwa')
      .use(HtmlPwaPlugin, [ cfg ])
  }
}
<commit_msg>feat(app): Further PWA improvements<commit_after>const appPaths = require('../../app-paths')
const PwaManifestPlugin = require('./plugin.pwa-manifest')

module.exports = function (chain, cfg) {
  // write manifest.json file
  chain.plugin('pwa-manifest')
    .use(PwaManifestPlugin, [ cfg ])

  let defaultOptions
  const WorkboxPlugin = require('workbox-webpack-plugin')
  const pluginMode = cfg.pwa.workboxPluginMode
  const log = require('../../helpers/logger')('app:workbox')

  if (pluginMode === 'GenerateSW') {
    const pkg = require(appPaths.resolve.app('package.json'))

    defaultOptions = {
      cacheId: pkg.name || 'quasar-pwa-app'
    }

    log('[GenerateSW] Will generate a service-worker file. Ignoring your custom written one.')
  }
  else {
    defaultOptions = {
      swSrc: appPaths.resolve.app(cfg.sourceFiles.serviceWorker)
    }

    log('[InjectManifest] Using your custom service-worker written file')
  }

  let opts = {
    ...defaultOptions,
    ...cfg.pwa.workboxOptions
  }

  if (cfg.ctx.mode.ssr) {
    opts.exclude.push('../vue-ssr-client-manifest.json')

    // if Object form:
    if (cfg.ssr.pwa && cfg.ssr.pwa !== true) {
      const merge = require('webpack-merge')
      opts = merge(opts, cfg.ssr.pwa)
    }


    if (pluginMode === 'GenerateSW') {
      if (!opts.directoryIndex) {
        opts.directoryIndex = cfg.build.publicPath
      }

      if (opts.runtimeCaching.every(entry => entry.urlPattern !== cfg.build.publicPath)) {
        opts.runtimeCaching.unshift({
          urlPattern: cfg.build.publicPath,
          handler: 'StaleWhileRevalidate'
        })
      }
    }
  }
  else if (!opts.navigateFallback) {
    opts.navigateFallback = `${cfg.build.publicPath}${cfg.build.htmlFilename}`
  }

  opts.swDest = 'service-worker.js'

  chain.plugin('workbox')
    .use(WorkboxPlugin[pluginMode], [ opts ])

  if (!cfg.ctx.mode.ssr) {
    const HtmlPwaPlugin = require('./plugin.html-pwa').plugin
    chain.plugin('html-pwa')
      .use(HtmlPwaPlugin, [ cfg ])
  }
}

{'fraction_non_alphanumeric': 0.15319572245710023, 'fraction_numerical': 0.0, 'mean_word_length': 2.8897485493230173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5909847', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1313, 'n_words': 230}