Skip to content

Commit

Permalink
Merge pull request #377 from developit/noServiceWorkerFile
Browse files Browse the repository at this point in the history
adding flag to disable service worker
  • Loading branch information
reznord authored Sep 26, 2017
2 parents b93aa1a + 7523fbb commit 81c7bb2
Show file tree
Hide file tree
Showing 4 changed files with 14 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
5 changes: 4 additions & 1 deletion src/lib/webpack/webpack-client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ function isProd(config) {
/push-manifest\.json$/,
/.DS_Store/
]
})
}),
new webpack.DefinePlugin({
'process.env.ADD_SW': config.serviceWorker
}),
]
};
}
Expand Down

0 comments on commit 81c7bb2

Please sign in to comment.