Skip to content

Commit

Permalink
chore: example using webpack (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored May 4, 2022
1 parent 9477581 commit 74d3c62
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ if ('serviceWorker' in navigator) {
}
```

## Use with Webpack

For using `nftstorage-service-worker` on your project bundle with webpack, look into [webpack example](./example/webpack/).

## References

- https://github.com/olizilla/see-other - a sw to resolve mutable dnslinks to their current immutable form for better caching.
Expand Down
1 change: 1 addition & 0 deletions example/webpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
2 changes: 2 additions & 0 deletions example/webpack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# nftstorage service worker using Webpack

21 changes: 21 additions & 0 deletions example/webpack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "nftstorage-service-worker-webpack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"start": "npm run build && serve dist"
},
"dependencies": {
"nftstorage-service-worker": "../.."
},
"devDependencies": {
"html-webpack-plugin": "^5.5.0",
"serve": "^13.0.2",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2"
},
"author": "",
"license": "MIT"
}
11 changes: 11 additions & 0 deletions example/webpack/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>

<head>
<title>Hello Webpack</title>
</head>
<body>
<img src="https://nftstorage.link/ipfs/bafybeidluj5ub7okodgg5v6l4x3nytpivvcouuxgzuioa6vodg3xt2uqle/olizilla.png" alt="olizilla" />
<script type="text/javascript" src="./app.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions example/webpack/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./nftstorage-sw.js');
}
13 changes: 13 additions & 0 deletions example/webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = () => ({
entry: {
'app': './src/index.js',
'nftstorage-sw': './node_modules/nftstorage-service-worker/src/nftstorage-sw.js',
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.html'
})
]
})

0 comments on commit 74d3c62

Please sign in to comment.