Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding flag to disable service worker #377

Merged
merged 2 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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