Skip to content

Commit

Permalink
adding flag to disable service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekbh committed Sep 19, 2017
1 parent da8e8ff commit c978a03
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ $ preact build
--src Entry file (index.js). [default: "src"]
--dest Directory root for output. [default: "build"]
--production, -p Create a minified production build. [default: true]
--no-prerender Disable pre-render of static app content.
--no-prerender Disable pre-render of static app content.
--service-worker Add a service worker to application. [default: true]
--prerenderUrls Path to pre-render routes configuration. [default "prerender-urls.json"]
--template Path to template file.
--clean Clear output directory before building. [default: true]
Expand Down Expand Up @@ -133,16 +134,16 @@ $ preact serve

### Templates

### Full:
### Full:

- Preact Router Included
- Dynamic routes

<a href="https://build-gqqxvrjtbx.now.sh/" target="_blank">Demo</a>

### Simple:
### Simple:

- Github API
- Github API
<a href="https://build-xsepqcgvue.now.sh/" target="_blank">Demo</a>

### Empty
Expand Down
4 changes: 4 additions & 0 deletions src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export default asyncCommand({
description: 'Path to pre-render routes configuration.',
default: 'prerender-urls.json'
},
'service-worker': {
description: 'Add a service worker to the application.',
default: true
},
clean: {
description: 'Clear output directory before building.',
default: true
Expand Down
2 changes: 1 addition & 1 deletion src/lib/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (process.env.NODE_ENV==='development') {
// enable preact devtools
require('preact/devtools');
}
else if ('serviceWorker' in navigator && location.protocol === 'https:') {
else if (process.env.ADD_SW && 'serviceWorker' in navigator && location.protocol === 'https:') {
navigator.serviceWorker.register('/sw.js');
}

Expand Down
7 changes: 6 additions & 1 deletion src/lib/webpack/webpack-client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ const production = config => addPlugins([
/push-manifest\.json$/,
/.DS_Store/
]
})
}),
new webpack.DefinePlugin({
'process.env': {
'ADD_SW': config['service-worker']
}
}),
]);

const htmlPlugin = (config, src) => {
Expand Down

0 comments on commit c978a03

Please sign in to comment.