2016-03-06 101 views
1

嗨我目前正在努力学习如何使用webpacks HMR表达沿后不工作,我每次更新和保存文件时,它给我的错误:HMR文件移动到/ app文件夹

”以下模块无法热更新:(需要全部重新加载)“ ”./app/components/App.js“

我的当前配置文件有什么问题吗?

所以我有这样的目录结构:

todos 
    | 
    app 
     | 
    package.son 
    server.js 
    webpack.config.js 

,我有一个webpack.config.js文件看起来像下面这样的server.js文件:

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'] 
    } 

}; 

服务器.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) 
    } 
}) 

回答

2

您是否试过接受该模块?在HMR的WebPack它documentation说以下内容:

A module can only be updated if you “accept” it. So you need to module.hot.accept the module in the parents or the parents of the parents. For example, a router or a subview would be a good place.

在index.js文件试试这个或任何模块你想HMR重装:

if (module.hot) { 
module.hot.accept(); 
} 
相关问题