如何让 webpack-dev-server 具有自定义值的传入请求超时



我有一个webpack配置文件,其中包含webpack-dev-server,如下所示。

const webpack = require('webpack');
module.exports = {
    devtool: 'inline-source-map',
    devServer: {
    disableHostCheck: true,
    historyApiFallback: true,
    compress: true,
    host: '0.0.0.0',
    port: 3000,
    publicPath: '/static/js/',
    proxy: {
        '**': {
            target: 'http://localhost.idincu.net:8080',
            secure: false,
            prependPath: false,
            proxyTimeout: 1000 * 60 * 10
            }
        }
    },
    plugins: [
        new webpack.NamedModulesPlugin()
    ]
}

现在,当我使用代理向后端服务器发送请求时,我得到了ECONNRESET。发生这种情况的原因可能是设置了 webpack-dev-server 的timeout

我已经深入研究了这个,以更改 webpack-dev-server 的超时设置。但我失败了。谁能给我一些建议?

我发现这样做的一些方法之一是在快递上设置超时。或者,如果有一种方法可以使用与我的配置文件对应的devServer.before属性,那对我来说将是一个好方法。

提前谢谢你。

在这里自我

回答。

只需像下面这样将timeout: 1000 * 60 * 10添加到devServer.proxy中即可使其工作。

const webpack = require('webpack');
const devConfig = {
    devtool: 'inline-source-map',
    devServer: {
        disableHostCheck: true,
        historyApiFallback: true,
        compress: true,
        host: '0.0.0.0',
        port: 3000,
        publicPath: '/static/js/',
        proxy: {
            '**': {
                target: 'http://localhost.idincu.net:8080',
                secure: false,
                prependPath: false,
                proxyTimeout: 1000 * 60 * 10,
                timeout: 1000 * 60 * 10
            }
        }
    },
    plugins: [
        new webpack.NamedModulesPlugin()
    ]
};
module.exports = devConfig;

最新更新