From 1443a131334e1f3f857a934ea192dca938e505c8 Mon Sep 17 00:00:00 2001 From: Dmitri Pyatkov Date: Sun, 8 Oct 2017 05:06:01 +0700 Subject: [PATCH] Update README.md (#103) --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6514c6b..7aaeeb6 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,21 @@ plugins: [ ``` ## Webpack Dev Server Support -Currently `SWPrecacheWebpackPlugin` will not work with `Webpack Dev Server`. If you wish to test the service worker locally, you can use simple a node server [see example project][example-project] or `python SimpleHTTPServer` from your build directory. I would suggest pointing your node server to a different port than your usual local development port and keeping the precache service worker out of your [local configuration (example)][webpack-local-config-example]. +Currently `SWPrecacheWebpackPlugin` will not work with `Webpack Dev Server`. If you wish to test the service worker locally, you can use simple a node server [see example project][example-project] or `python SimpleHTTPServer` from your build directory. I would suggest pointing your node server to a different port than your usual local development port and keeping the precache service worker out of your [local configuration (example)][webpack-local-config-example]. + +Or add `setup` section to `devServer` config, e.g.: +``` +module.exports = { + devServer: { + setup: function (app) { + app.get('/service-worker.js', function (req, res) { + res.set({ 'Content-Type': 'application/javascript; charset=utf-8' }); + res.send(fs.readFileSync('build/service-worker.js')); + }); + } + } +} +``` There will likely never be `webpack-dev-server` support. `sw-precache` needs physical files in order to generate the service worker. Webpack-dev-server files are in-memory. It is only possible to provide `sw-precache` with globs to find these files. It will follow the glob pattern and generate a list of file names to cache.