无法让webpack热中间件与react / redux一起使用

时间:2016-07-15 19:31:53

标签: javascript express webpack

IM拔出毛发试图让热重装工作。我运行node server.js时会加载我的项目,但文件没有被热重新加载。

server.js

// webpack stuff
var webpack = require("webpack");
var webpackDevMiddleware = require("webpack-dev-middleware");
var webpackHotMiddleware = require("webpack-hot-middleware");
var config = require("./webpack.config");
var compiler = webpack(config);

// email template
var emailTemplate = require("./emailTemplate");

// express
var express = require("express");
var app = express();
var crypto = require("crypto");
var bodyParser = require("body-parser");
var cookieParser = require("cookie-parser");
var port = 8000;

app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: config.output.publicPath }));
app.use(webpackHotMiddleware(compiler));
app.use(express.static(__dirname + "/src"));

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cookieParser());
....... shorten for security

webpack.config.js

var webpack = require('webpack');

module.exports = {
  entry: [
    'webpack/hot/dev-server',
    'webpack-hot-middleware/client',
    './src/index.js'
  ],
  output: {
    path: __dirname + '/src/build',
    filename: 'bundle.js',
    public: '/',
    publicPath: 'http://localhost:8000/public/'
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        loaders: ['babel'],
        exclude: /node_modules/,
        include: __dirname + '/src'
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader!postcss-loader'
      },
      {
        test: /\.(png|jpg|jpeg|gif|woff)$/,
        loader: 'url-loader?limit=8192'
      }
    ]
  },
  jest: {
    moduleFileExtensions: ["js", "jsx"]
  },
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ]
};

如果有其他文件可供查看,请与我们联系。

0 个答案:

没有答案