Skip to content

Browser not refreshing when using the Node API #994

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
peripateticus opened this issue Jul 14, 2017 · 1 comment
Closed

Browser not refreshing when using the Node API #994

peripateticus opened this issue Jul 14, 2017 · 1 comment

Comments

@peripateticus
Copy link

peripateticus commented Jul 14, 2017

Do you want to request a feature or report a bug? Bug

What is the current behavior?
The code is compiling correctly, however, the browser does not refresh when updating source code. I must manually refresh the browser. I've tried various options with no luck (hot, polling, etc).

When I run using the CLI with the same .conf file, the browser does refresh automatically.

If the current behavior is a bug, please provide the steps to reproduce.

Pretty straightforward code:

Code to start webpack-dev-server

const WDS = require('webpack-dev-server');
const path = require('path');
const webpack = require('webpack');

/**
 * Start webpack dev server.
 */
const wpds = () => {

  const conf = require('./webpack.dev.conf.js');
  const compiler = webpack(conf);
  const port = 8080;
  const cwd = process.cwd();

  const server = new WDS(compiler, {
    port,
    contentBase: path.resolve(cwd, '..', 'dest'),
    publicPath: '/dest/',
  });
  server.listen(port, '127.0.0.1', () => {
    console.log(`Starting server on http://localhost:${port}`);
  });
};


wpds();

webpack.dev.conf.js

const path = require('path');

module.exports = {

  entry: {
    app: path.resolve(__dirname, '../entry.js'),
  },

  output: {
    path: path.resolve(__dirname, '../dest'),
    filename: '[name].bundle.js',
  },

  // I comment out the devServer entry out when running via the node API.
  //devServer: {
  //  contentBase: path.resolve(__dirname, '../dest'),
  //  publicPath: '/dest/',
  //  compress: true,
  //  port: 9000,
  // open: true,
  //  openPage: '',
  //},
};

What is the expected behavior?
Browser updates when source code changes.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention your webpack and Operating System version.
webpack v3.2.0 (wasn't working in v3.1.0 either)
webpack-dev-server 2.5.1
MacOS Sierra 10.12.5

@peripateticus
Copy link
Author

peripateticus commented Jul 14, 2017

The solution to this seems to be related to this stack overflow question/answer: https://stackoverflow.com/questions/43747636/live-reloading-in-webpack-dev-server-when-using-node-js-api

and

https://github.com/webpack/webpack-dev-server/blob/master/examples/node-api-simple/webpack.config.js

So, the entry that I used to get this working was:

entry: {
    app: [
      'webpack-dev-server/client?http://localhost:8080',
      path.resolve(__dirname, '../entry.js'),
    ],
  },

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

1 participant