D
D
Dmitry Kravchenko2016-04-21 11:14:49
JavaScript
Dmitry Kravchenko, 2016-04-21 11:14:49

React and hmr, why doesn't Webpack rebuild the project?

Hello!
I want to start using webpack to build a React project. First, my config:

var path = require('path');
var webpack = require('webpack');

module.exports = {
  entry: [
    'webpack-dev-server/client?http://localhost:4567',
    'webpack/hot/only-dev-server',
    './src/index'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/static/'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ],
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['react-hot', 'babel'],
      include: [path.join(__dirname, 'src')]
    }]
  }
};

and file system
src
--app
----actions
----components
----constants
----reducers
----app.js
----config.js
--index.js

I ran into a problem: hot module replacement only works if the react modules are located directly in ./src, otherwise webpack does not react at all to file changes (in the app/components folder, for example). What is my problem?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2016-04-21
@maxfarseer

The config is a bit old. I dug out my config with a similar version, I don’t see any special differences. Unless the module include specifies the directory at once, and not an array element.

{ test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loaders: ['react-hot','babel?stage=0&optional=runtime&plugins=typecheck'],
        include: path.join(__dirname, 'src/js')
      },

The full config is here (do not look that it is .hot, it was just made for convenience out of ignorance)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question