无法关闭webpack HMR

时间:2017-01-03 15:17:32

标签: javascript node.js webpack

使用express 4.14.0,webpack 1.14.0 w / babel和预设。这是我在某处找到的样板webpack配置:

var path = require('path');

module.exports = {
  entry: './main.js',
  output: { path: __dirname, filename: 'bundle.js' },
  module: {
    loaders: [
      {
        test: /.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['es2015', 'react']
        }
      }
    ]
  },
};

bundle.js由Express提供,我的app.js是使用express-generator生成的:

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;

我只包含app.js的内容,以表明,据我所知,没有任何内容可以引用HMR。

我像往常一样在nodemon bin/www旁边运行webpack -d --watch,在我浏览器中打开页面之前,有些事情正在向/__webpack_hmr提出一致请求并获得404.如何阻止此操作?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。但我只是改变了端口然后它工作了。也许是因为我在同一个端口上运行了webpack的其他项目。因此,请尝试更改PORT,看看是否可以帮助您。