Skip to content

Commit

Permalink
Add web pack configuration to generate progressive web app code durin…
Browse files Browse the repository at this point in the history
…g build
  • Loading branch information
ceddlyburge committed Jun 22, 2018
1 parent ab5fd02 commit 2531646
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
"license": "ISC",
"devDependencies": {
"webpack-cli": "^3.0.8"
},
"dependencies": {
"sw-precache-webpack-plugin": "^0.11.5",
"webpack-pwa-manifest": "^3.6.2"
}
}
2 changes: 1 addition & 1 deletion src/Main.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Html

main : Html.Html msg
main = Html.text "Hello World"
main = Html.text "Hello World Progessive with WebPack"
8 changes: 8 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
<head>
<meta charset="utf-8" />
<title>Elm SPA example</title>
<link rel="manifest" href="/manifest.json">
</head>
<body>
<div id="main"></div>
<script src="/app.js"></script>
<script>
if('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/service-worker.js')
.then(function() { console.log("Service Worker Registered"); });
}
</script>
</body>
</html>
Binary file added src/static/img/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var path = require("path");
var SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
var WebpackPwaManifest = require('webpack-pwa-manifest');

module.exports = {
entry: {
Expand Down Expand Up @@ -29,6 +31,34 @@ module.exports = {
noParse: /\.elm$/,
},

plugins: [
new SWPrecacheWebpackPlugin(
{
cacheId: 'ceddlyburge/progressive-elm',
dontCacheBustUrlsMatching: /\.\w{8}\./,
filename: 'service-worker.js',
minify: false,
navigateFallback: 'index.html',
staticFileGlobsIgnorePatterns: [/\.map$/, /manifest\.json$/]
}
)
, new WebpackPwaManifest({
name: 'Minimal progressive Elm App, to demonstrate the steps involved',
short_name: 'Progessive Elm',
description: 'Minimal progressive Elm App. There is a Hello World page, with no images or css, so that there is less noise to detract from the code that is required to make it progressive.',
background_color: '#ffffff',
theme_color: '#000000',
start_url: '/',
icons: [
{
src: path.resolve('src/static/img/icon.png'),
sizes: [192],
destination: path.join('static', 'img')
}
]
})
],

devServer: {
inline: true,
stats: { colors: true },
Expand Down

0 comments on commit 2531646

Please sign in to comment.