serviceworker-webpack-plugins

1.3.0 • Public • Published

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)

Readme

Keywords

Package Sidebar

Install

npm i serviceworker-webpack-plugins

Weekly Downloads

3

Version

1.3.0

License

MIT

Unpacked Size

12.3 kB

Total Files

11

Last publish

Collaborators

  • a657850144