1 | const path = require('path')
|
2 |
|
3 | const { getOptions } = require('./options')
|
4 | const { readJSFiles } = require('./utils')
|
5 |
|
6 | module.exports = function nuxtWorkbox (moduleOptions) {
|
7 | this.nuxt.hook('build:before', () => {
|
8 |
|
9 | const options = getOptions.call(this, moduleOptions)
|
10 |
|
11 |
|
12 | if (options.dev) {
|
13 | console.warn('`workbox.dev` enabled. Remember to clean application data and unregister service workers in your browser or you will experience infinity loop!')
|
14 | }
|
15 |
|
16 |
|
17 | if (options.autoRegister) {
|
18 | this.addPlugin({
|
19 | src: path.resolve(__dirname, '../templates/sw.register.js'),
|
20 | ssr: false,
|
21 | fileName: 'sw.register.js',
|
22 | options: {
|
23 | ...options
|
24 | }
|
25 | })
|
26 | }
|
27 |
|
28 |
|
29 | if (options.swTemplate) {
|
30 | this.addTemplate({
|
31 | src: options.swTemplate,
|
32 | fileName: options.swDest,
|
33 | options: {
|
34 | ...options,
|
35 | routingExtensions: readJSFiles.call(this, options.routingExtensions),
|
36 | cachingExtensions: readJSFiles.call(this, options.cachingExtensions),
|
37 | workboxExtensions: readJSFiles.call(this, options.workboxExtensions)
|
38 | }
|
39 | })
|
40 | }
|
41 | })
|
42 | }
|
43 |
|
44 | module.exports.meta = require('../package.json')
|