oliviertassinari / serviceworker-webpack-plugin

Simplifies creation of a service worker to serve your webpack bundles. :recycle:
https://oliviertassinari.github.io/serviceworker-webpack-plugin/
MIT License
458 stars 76 forks source link

How to use this plugin with webpack-dev-server #66

Open 4lph4-Ph4un opened 6 years ago

4lph4-Ph4un commented 6 years ago

Hi!

I'm wondering how to use this plugin with webpack-dev-server? I get this to work beautifully when applying production builds using webpack -p build command, but when I try to use this with dev-server, the client will not naturally find the output js-file (hence -it's not actually produced in server-mode)

Here's my current plugins and their settings:

plugins: [ 
  new BundleAnalyzerPlugin(),
  new ServiceWorkerWebpackPlugin({
    entry:    `${APP_DIR}/service-worker.js`,
    filename: "../service-worker.js",
    excludes: [ "**/.*", "**/*.map", "*.html" ],
   })
  new webpack.NamedModulesPlugin(), // Named Modules for DEV:
  new webpack.HotModuleReplacementPlugin(),
  new webpack.optimize.CommonsChunkPlugin({
    name: [ "vendor", "polyfills" ]
  }),
  new HtmlWebpackPlugin({
    filename:          "../index.html",
    title:             "Learning Diary Project",
    template:          `${APP_DIR}/index.ejs`,
    alwaysWriteToDisk: true
  }),
  new HtmlWebpackHarddiskPlugin(),
 ]
woutervanvliet commented 6 years ago

Would you be able to setup a repo that reproduces the issue with the least amount of code necessary?