3

I am using webpack-dev-middleware along with expressjs to watch and serve files emitted from webpack.

Have setup expressjs server with nodemon so that it can watch any server code changes.

The issue is, for any change detected by nodemon, the server restart also triggers a new webpack-dev-middleware execution which then rebuilds the entire client bundle.

Express server snippet used in development:

const express = require('express');
const webpackConfig = require('./webpack.config.js');

const app = express();
const compiler = require('webpack')(webpackConfig);
const devMiddlewareInstance = require('webpack-dev-middleware')(compiler, {
  publicPath: webpackConfig.output.publicPath,
});

app.use(devMiddlewareInstance);

app.listen(300, function() {
  console.log('App listening on port 3000!\n');
});

Is there any way to prevent the execution of webpack-dev-middleware for every restart triggered by nodemon ?

Easwar
  • 5,132
  • 1
  • 11
  • 21
  • same issue have you any idea for resolving that ? – Kalifornium Dec 05 '19 at 20:03
  • @Kalifornium : Nope. This is as per design of `nodemon` and as it restarts the entire node process `webpack-dev-middleware` can do nothing about it. The workaround would be to keep it in a different static server and maintain another nodemon server for APIs. That is what `webpack-dev-server` is doing. – Easwar Dec 06 '19 at 07:10
  • ok then , we should open an issue for that !, i've tried Chokidar it's better for some features ! – Kalifornium Jan 23 '20 at 07:39

0 Answers0