简体   繁体   English

Webpack dev服务器热模式无法正常工作

[英]Webpack dev server hot mode not working

Heres my config: 继承我的配置:

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

And here's the gulp task im running: 这是我正在运行的gulp任务:

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? 我在这做错了什么?

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 您需要将<script src="http://localhost:8080/webpack-dev-server.js"></script>到index.html。使用API​​时不会添加它

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

maybe you also need to add 'webpack/hot/dev-server' as an entrypoint to your webpack config 也许你还需要添加'webpack/hot/dev-server'作为webpack配置的入口点

be sure to set 一定要设置

webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin());

in the webpackConfig as well 在webpackConfig中也是如此

If you are using redux can try this. 如果你使用redux可以尝试这个。

For some random reason redux-devtools was not allowing hot reload for me. 由于一些随机的原因, redux-devtools不允许我进行热重装。 Try removing it from root component and redux compose config. 尝试从root组件中删除它并使用redux compose配置。

Note: Use redux devtool browser extension with this config in your store configuration: window.devToolsExtension ? window.devToolsExtension() : f => f 注意:在商店配置中使用带有此配置的redux devtool浏览器扩展: window.devToolsExtension ? window.devToolsExtension() : f => f window.devToolsExtension ? window.devToolsExtension() : f => f

Also, must read: https://medium.com/@rajaraodv/webpacks-hmr-react-hot-loader-the-missing-manual-232336dc0d96#.ejpsmve8f 此外,必须阅读: https//medium.com/@rajaraodv/webpacks-hmr-react-hot-loader-the-missing-manual-232336dc0d96#.ejpsmve8f

Or try hot reload 3: example: https://github.com/gaearon/redux-devtools/commit/64f58b7010a1b2a71ad16716eb37ac1031f93915 或尝试热重载3:示例: https//github.com/gaearon/redux-devtools/commit/64f58b7010a1b2a71ad16716eb37ac1031f93915

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM