Greetings, I am currently in the process of learning how to utilize express with webpacks HMR feature. However, every time I make changes and save a file, I encounter the following error:
"The following modules couldn't be hot updated: (Full reload needed)" "./app/components/App.js"
I am wondering if there is an issue with my configuration files. Here is the directory structure I am working with:
todos
|
app
|
package.son
server.js
webpack.config.js
In this directory, I have a webpack.config.js file and a server.js file that are structured as follows:
var path = require('path');
var webpack = require('webpack');
module.exports = {
context: path.join(__dirname + "/app"),
entry: ['./index'],
output: {
path: "/bundle",
publicPath: '/static/',
filename: "bundle.js"
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['react', 'es2015']
}
}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
}
};
server.js
var webpack = require('webpack')
var webpackDevMiddleware = require('webpack-dev-middleware')
var webpackHotMiddleware = require('webpack-hot-middleware')
var config = require('./webpack.config')
var app = new (require('express'))()
var port = 3000
var compiler = webpack(config)
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: config.output.publicPath }))
app.use(webpackHotMiddleware(compiler))
app.get("/", function(req, res) {
res.sendFile(__dirname + '/app/index.html')
})
app.listen(port, function(error) {
if (error) {
console.error(error)
} else {
console.info("==> 🌎 Listening on port %s. Open up http://localhost:%s/ in your browser.", port, port)
}
})