1.3.0 • Published 5 years ago

serviceworker-webpack-plugins v1.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

serviceworker-webpack-plugins

Simplifies creation of serviceworker files to serve your PWA.

Usage

  • install
$ npm i serviceworker-webpack-plugins --save-dev
  • setup

webpack.config.js

const ServiceworkerPlugins = require('serviceworker-webpack-plugins')

module.exports = {
  // ...
  plugins: [
    new ServiceworkerPlugins({
      entry: {
        sw: {
          filename: 'sw.js',
          path: ''
        },
        register: {
          filename: 'sw-register.js',
          path: ''
        }
      },
      include: [] // [PATH] exclude cacheFiles path
    })
  ]
}

Note

Please pay attention before use:

Insert the following script tag below your body node

<script>
    let script = document.createElement('script')
    let el = document.body.getElementsByTagName('script')[0]
    script.src = `./sw.js?v=${Date.now()}`
    el.parentNode.insertBefore(script,el)
</script>

Local debugging

Key Points

createChildCompiler

/**
 * @params compilerName
 * @params outputOptions
**/
const childCompiler = compilation.createChildCompiler(compilerName,outputOptions)
1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago