Webpack dev服务器热模式无法正常工作 [英] Webpack dev server hot mode not working

查看:124
本文介绍了Webpack dev服务器热模式无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继承我的配置:

devServer: {
    contentBase: '/web/dist/',
    hot: true,
    stats: {colors: true},
    inline: true
}

这是我正在运行的gulp任务:

And here's the gulp task im running:

gulp.task('build', ['clean', 'styles', 'bower', 'media', 'data', 'homepage'], function(done) {
    es6promise.polyfill();

    console.log('STARTING DEV SERVER...');

    server = new WebpackDevServer(webpack(webpackDevConfig), webpackDevConfig.devServer);
    server.listen(8080, '0.0.0.0', function (err, stats) {
        if (err) {
             throw new gutil.PluginError("webpack-dev-server", err);
        }

        console.log('DEV SERVER STARTED');

        done();
    });
});

除了热加载(当我对文件进行更改时没有刷新或更改),一切都按预期工作。我在这里做错了什么?

Everything works as expected except the hot loading (no refresh or change when I make changes to files). What am I doing wrong here?

推荐答案

你需要添加< script src =http: //localhost:8080/webpack-dev-server.js\"></script> 到你的index.html使用API​​时不会添加它

You need to add <script src="http://localhost:8080/webpack-dev-server.js"></script> to your index.html It is not added when you use the API

请注意,webpack配置未传递给WebpackDevServer API,因此在这种情况下不使用webpack配置中的devServer选项。此外,WebpackDevServer API没有内联模式。< ;脚本src =http:// localhost:8080 / webpack-dev-server.js>< / script> 应手动插入HTML页面。
http://webpack.github.io/docs/webpack-dev-server.html

"Notice that webpack configuration is not passed to WebpackDevServer API, thus devServer option in webpack configuration is not used in this case. Also, there is no inline mode for WebpackDevServer API. <script src="http://localhost:8080/webpack-dev-server.js"></script> should be inserted to HTML page manually." (http://webpack.github.io/docs/webpack-dev-server.html)

也许您还需要添加'webpack / hot / dev-server'作为您的webpack配置的入口点

maybe you also need to add 'webpack/hot/dev-server' as an entrypoint to your webpack config

这篇关于Webpack dev服务器热模式无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆