goldhand / goldhand/sw-precache-webpack-plugin

Provide option to auto generate register bundle script

Open
#65 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
1.4k
Forks
101
PR merge metrics
No merged PRs in 30d

Description

When a user opts in, emit a bundle with a registration script.

API:
```javascript
...
output: {
path: path.resolve(__dirname, 'dist/'),
filename: '[name]-[hash].js',
publicPath: 'http://localhost:3000/',
},
plugins: [
new SWPrecacheWebpackPlugin(
{
cacheId: 'my-project-name',
filename: 'my-service-worker.js'
register: true,
}
),
],
...
```

emits: `dist/register-sw-[hash].js`
```
(function() {
if('serviceWorker' in navigator) {
navigator.serviceWorker.register('http://localhost:3000/my-service-worker.js');
}
})();
```

This has the added benefit of being picked up by webpack template plugins that inject all bundles into an html template (html-webpack-plugin #62)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.