Skip to content

Npm Run Dev: Modify Vue Webpack Template Dev Server to use --watch-poll #432

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

Closed
necevil opened this issue Jan 4, 2017 · 12 comments
Closed

Comments

@necevil
Copy link

necevil commented Jan 4, 2017

I am running the webpack portion of this template stack inside of a docker container I created, which also contains the vue CLI (https://hub.docker.com/r/ncevl/webpack-vue/). However, hot-reload does not work after moving from the webpack-simple template to this one.

Everything was working using the Webpack-Simple template which you can see over here: https://github.com/vuejs-templates/webpack-simple

I was able to get the simple template running (with hot-reload working as intended) with the following webpack-development-server launch command:
webpack-dev-server --hot --inline --progress --host 0.0.0.0 --watch-poll

The full version of the webpack template does not appear to use a webpack-dev-server launch command and instead appears to use additional middleware as referenced in build/dev-server.js (https://github.com/vuejs-templates/webpack/blob/master/template/build/dev-server.js) and the webpack dev config.

Since the --watch-poll was the key to getting the WDS hot-reload functionality to work within a docker container in the last project, my thinking is that I need to do something similar with the webpack-hot-middleware but I dont see anything in their docs (over here: https://github.com/glenjamin/webpack-hot-middleware) that talks about changing to a polling based approach.

I am wondering if anyone has run into anything similar or has any ideas. I guess my alternative would be roll back to a more basic webpack config and rebuild that portion of things to use the traditional webpack-dev-server.

@LinusBorg
Copy link
Contributor

LinusBorg commented Jan 7, 2017

Watching is The job of webpack-dev-middleware.

You can see the poll option in the example config here:

https://github.com/webpack/webpack-dev-middleware/blob/master/README.md

@LinusBorg
Copy link
Contributor

@necevil does that answer your question?

@necevil
Copy link
Author

necevil commented Jan 16, 2017

@LinusBorg Yep!
Thanks for pointing me in the right direction, the portion that I ended up needing (incase anyone else stumbles on this thread) was to add the following to the webpack-dev-middleware config:

    watchOptions: {
        aggregateTimeout: 300,
        poll: true
    },

As it turned out I was able to make it work WITHOUT the above, but when I went to deploy my same configuration to some of our other team members they required the above polling modification to make the dockerized webpack-dev-middleware server aware of changes to files on the local host / docker volume.

Without the above wdm would not notice the changes and trigger a new build, with the above added everything worked as intended.

For those who are confused as to exactly where to add that snippet, it needs to go inside of the dev-server.js file which is located inside of the build directory within this template. The code block you are looking to modify should end up looking like this (around line 22-24ish):

var devMiddleware = require('webpack-dev-middleware')(compiler, {
  publicPath: webpackConfig.output.publicPath, //was publicPath: webpackConfig.output.publicPath,
  quiet: true,
  watchOptions: {
      aggregateTimeout: 300,
      poll: 1000
  }
})

Thanks Linus!

@matthewpennell
Copy link

Thanks @necevil - your comment seems to be the only place on the entire web that concisely explains how to make this work. 👍

@necevil
Copy link
Author

necevil commented Feb 12, 2017

Stoked to hear it @matthewpennell

Hoping took notes to document for the team, hoping to blog it eventually but this is pretty much the nuts and bolts of the tricky portion.

@idhamhafidz
Copy link

I ignore running npm run dev in vagrant ssh. Just use normal terminal

@ghost
Copy link

ghost commented Feb 17, 2017

thanks @necevil
Can conform fix worked in my vagrant env as well.

@alexsandro-xpt
Copy link

Thank all, work for me.

@arthuralmeidap
Copy link

@necevil Thanks!! That's worked for me too!

@ghost
Copy link

ghost commented Sep 17, 2017

Thx.

@heronrs
Copy link

heronrs commented Nov 25, 2017

Currently running vue-cli v 2.9.1 and what worked for me was setting poll: 500 on conf/index.js

    errorOverlay: true,
    notifyOnErrors: true,
    poll: 500, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

If loading your app is taking too long on the browser, set it to a higher number like 1000, 1500

@shahidkarimi
Copy link

The webpack.mix file is a hell of code where to place this code

var devMiddleware = require('webpack-dev-middleware')(compiler, { publicPath: webpackConfig.output.publicPath, //was publicPath: webpackConfig.output.publicPath, quiet: true, watchOptions: { aggregateTimeout: 300, poll: 1000 } })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants