https://github.com/stealjs/steal-serviceworker
Creates a service worker for your steal-tools app.
https://github.com/stealjs/steal-serviceworker
service-worker stealjs
Last synced: 2 months ago
JSON representation
Creates a service worker for your steal-tools app.
- Host: GitHub
- URL: https://github.com/stealjs/steal-serviceworker
- Owner: stealjs
- License: mit
- Created: 2017-08-25T03:42:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-02T18:01:41.000Z (over 1 year ago)
- Last Synced: 2025-01-21T03:43:15.115Z (4 months ago)
- Topics: service-worker, stealjs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/steal-serviceworker
- Size: 2.34 MB
- Stars: 2
- Watchers: 7
- Forks: 0
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# steal-serviceworker
[](https://www.bitovi.com/community/slack?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://forums.bitovi.com/?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://github.com/stealjs/steal-serviceworker/blob/master/LICENSE.md)
[](https://badge.fury.io/js/steal-serviceworker)
[](https://coveralls.io/github/stealjs/steal-serviceworker?branch=master)
[](https://travis-ci.org/stealjs/steal-serviceworker)
[](https://greenkeeper.io/)`steal-serviceworker` helps you to create a service worker for your app that’s built with [steal-tools](https://stealjs.com/docs/steal-tools.html).
## Requirements
NodeJS 6+## Usage
**build.js**
```js
const stealTools = require("steal-tools");
const precache = require("steal-serviceworker");stealTools.build({
config: __dirname + "/basics/package.json!npm"
}).then(function(buildResult){
precache(buildResult);
});
```**index.html**
```html```
It's that easy?
## API
### precache(bundleResult, [options]) => [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
`precache` does two things for you:
- Generates a service worker that contains all the files that steal-tools bundles into the [dest folder](https://stealjs.com/docs/steal-tools.build.html#dest)
- Creates a basic [service worker registration](templates/service-worker-registration.tmpl). `precache` can put this code into its own file or prepend the code into `steal.production.js` for you.#### buildResult
The [BuildResult](https://stealjs.com/docs/steal-tools.BuildResult.html) obtained from calling [stealTools.build](https://stealjs.com/docs/steal-tools.build.html).
#### options
An optional object for specifying additional options. They are:
##### `bundleRegistration` [boolean]
Write the [service worker registration](templates/service-worker-registration.tmpl) template into `steal.production.js` or not.
If `false` the registration code gets written into a file named `service-worker-registration.js` into the [dest folder](https://stealjs.com/docs/steal-tools.build.html#dest). You have to include the registration script yourself
``Default: `false`
##### `cacheRegistration` [boolean]
Defines if the [service worker registration](templates/service-worker-registration.tmpl) code is cached by the service worker as well.
This option only make sense if `bundleRegistration` is `false`.##### `filename` [string]
The name of the service worker file.Default: `service-worker.js`
##### `registrationTemplate` [string]
You can use your own registration for the service worker.
E.g. you can handle the `state` of the service worker and can implement your own custom behaviors if the content of the cache changed.Default: `path.join(__dirname, "service-worker-registration.tmpl")`
##### all options provided by [Google’s sw-precache](https://github.com/GoogleChrome/sw-precache)
like
```js
precache(buildResult, {
staticFileGlobs: [
path.join(__dirname, "dist", '**', '*.*'),
path.join(__dirname, "src", "styles.css")
],
runtimeCaching: [{
urlPattern: "/",
handler: "networkFirst"
}]
});
```## Changelog
See the [latest releases on GitHub](https://github.com/stealjs/steal-serviceworker/releases).
## License
[MIT](https://github.com/stealjs/steal-serviceworker/blob/master/LICENSE.md)