-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
executable file
·74 lines (63 loc) · 1.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
let mix = require('laravel-mix');
class Workbox {
/**
* The optional name to be used when called by Mix.
* Defaults to the class name, lowercased.
*
* @return {String|Array}
*/
name() {
return ['generateSW', 'injectManifest'];
}
/**
* All dependencies that should be installed by Mix.
*
* @return {Array}
*/
dependencies() {
this.requiresReload = `Workbox webpack plugin has now been installed. Please run "npm run dev" again.`;
return ['workbox-webpack-plugin'];
}
/**
* Register the component.
*
* When your component is called, all user parameters
* will be passed to this method.
*
* @param {Object} config
* @return {void}
*
*/
register(config = {}) {
this.pluginName = this.caller[0].toUpperCase() + this.caller.slice(1);
this.config = config;
}
/**
* Boot the component. This method is triggered after the
* user's webpack.mix.js file has executed.
*/
boot() {
let workboxPlugin = require('workbox-webpack-plugin');
this.plugin = new workboxPlugin[this.pluginName](Object.assign({
swDest: 'service-worker.js'
}, this.config));
}
/**
* Plugins to be merged with the master webpack config.
*
* @return {Array|Object}
*/
webpackPlugins() {
return this.plugin;
}
/**
* Override the underlying webpack configuration.
*
* @param {Object} webpackConfig
* @return {void}
*/
webpackConfig(webpackConfig) {
webpackConfig.output.publicPath = '';
}
}
mix.extend(['generateSW', 'injectManifest'], new Workbox());