【问题标题】:How to resolve webpackwarning 'Cannot find update. Need to do a full reload'?如何解决 webpackwarning '找不到更新。需要完全重新加载吗?
【发布时间】:2016-10-20 02:45:16
【问题描述】:

我正在使用 webpack 和 gulp 运行我的 reactjs 应用程序,这是我的 gulpfile 的一个片段:

gulp.task("webpack-dev-server", function(callback) {
    // modify some webpack config options
    var myConfig = Object.create(webpackConfig);
    myConfig.devtool = "eval";
    myConfig.debug = true;

    // Start a webpack-dev-server
    new WebpackDevServer(webpack(myConfig), {
        //publicPath: "/" + myConfig.output.publicPath,
        inline: 'true',
        stats: {
            colors: true
        },
        hot:true,

    }).listen(9090, "localhost", function(err) {
        if (err) throw new gutil.PluginError("webpack-dev-server", err);
        gutil.log("[webpack-dev-server]", "http://localhost:9090/webpack-dev-server/index.html");
    });
});

这是我的 webpack.config.js:

module.exports = {
    entry: ["./app/app.js",
      'webpack/hot/only-dev-server', // "only" prevents reload on syntax errors
    ],
    output: {
        path: path.resolve(__dirname, "dist"),
        publicPath: "/dist/js",
        filename: "http://localhost:9090/dist/js/myapp.js",
        sourceMapFilename: "myapp.map"
    },
    devtool: '#source-map',
    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ],
    module: {
        loaders: [
        {
            loader: 'babel',
            exclude: /node_modules/
        }]
    },
    devServer: {
        inline: true
    }
}

当页面重新加载时,chrome devtools 显示以下错误:

bootstrap 04b58fb…:25 GET http://localhost:9090/dist/04b58fb8512c7a3f39f8.hot-update.json 404 (Not Found)hotDownloadManifest @ bootstrap 04b58fb…:25hotCheck @ bootstrap 04b58fb…:244check @ only-dev-server.js:12(anonymous function) @ only-dev-server.js:70
only-dev-server.js:27 [HMR] Cannot find update. Need to do a full reload!
only-dev-server.js:28 [HMR] (Probably because of restarting the webpack-dev-server)

如何解决这个问题,以便重新加载页面?

【问题讨论】:

    标签: reactjs gulp webpack-dev-server


    【解决方案1】:

    你试过了吗:

    if (module.hot) 
        module.hot.accept();
    

    webpack 本身不会更新任何模块,你必须接受它。

    https://webpack.github.io/docs/hot-module-replacement-with-webpack.html#what-is-needed-to-use-it

    【讨论】:

    • 只是一个代码 sn-p 没有正确指导如何以及在哪里使用它是没有用的。
    猜你喜欢
    • 2017-06-24
    • 1970-01-01
    • 2019-10-25
    • 2016-10-03
    • 2018-12-20
    • 1970-01-01
    • 2013-10-31
    • 2022-11-03
    • 1970-01-01
    相关资源
    最近更新 更多