Adds Service Worker Precache support to brunch.
Install the plugin via npm with npm install --save-dev sw-precache-brunch
.
Or, do manual install:
- Add
"sw-precache-brunch": "~x.y.z"
topackage.json
of your brunch app. - If you want to use git version of plugin, use the GitHub URI
"sw-precache-brunch": "denar90/sw-precache-brunch"
.
Filename for service worker.
It will be placed into destination (public) brunch folder.
Default: 'sw.js'
This option gives possibility to add and register
service worker into html
asset files.
If value set as
true
service worker will be added and registered to ALLhtml
assets automatically.
Config example:
swPrecache: {
'swFileName': 'service-worker.js',
'autorequire': true
}
swPrecache: {
'autorequire': ['app/assets/index.html']
}
Default: false
Options for sw-precache
.
Look at all sw-precache
available options.
Default: {staticFileGlobs: ['public/**/*.*']}
If you don't pass any configuration properties it will cache all files in your
public
folder and createsw.js
. All what you need is register service worker for your app.
###Config example
module.exports = {
files: {
javascripts: {
joinTo: {
'vendor.js': /^(?!app|test)/,
'app.js': /^app/,
'test.js': /^test/
}
},
stylesheets: {joinTo: 'app.css'},
},
plugins: {
babel: {presets: ['es2015']},
swPrecache: {
swFileName: 'service-worker.js',
options: {
staticFileGlobs: [
'public/app.css',
'public/app.js',
'public/index.html'
],
stripPrefix: 'public/'
}
}
}
};
module.exports = {
plugins: {
...
swPrecache: {
autorequire: ['app/assets/index.html']
}
...
}
};
MIT © Artem Denysov