webpack-dev-server sock-js错误的网址

时间:2017-10-04 00:17:26

标签: javascript webpack webpack-dev-server

我遇到的问题是我的webpack-dev-server实例正在侦听我的Web服务器的不同URL。 Web服务器在http://dev.foo.com/上,而webpack正在侦听localhost:8080。我在我的网络服务器上的app.bundle.js标记中加入了<head>

问题是webpack正在尝试连接到http://dev.foo.com:8080/sockjs-node/info?t=1507075303656并且正在接收net::ERR_CONNECTION_REFUSED而不是与http://localhost:8080/sockjs-...的连接

我不能为我的生活弄清楚是否有可能更改此网址,大多数答案似乎都表明我需要更改entry: ['webpack-dev-server/client'],但这并非如此。似乎对我有用。

这是我的webpack配置。

// webpack.common.js
const path = require('path');

module.exports = {
    entry: ['./js/application.js'],
    output: {
        path: path.resolve(__dirname, './build'),
        filename: 'app.bundle.js'
    },
    module: {
        rules: [
            { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
            { test: /\.jsx$/, loader: 'babel-loader', exclude: /node_modules/ }
        ]
    }
}
// webpack.dev.js
const merge = require('webpack-merge');
const common = require('./webpack.common.js');

module.exports = merge(common, {
    entry: ['webpack-dev-server/client?http://127.0.0.1:8080/'],
    module: {
        rules: [
            {
                test: /\.scss$/,
                use: [
                    { loader: "style-loader" },
                    { loader: "css-loader" },
                    { loader: "sass-loader" }
                ]
            },
            { test: /\.(eot|svg|ttf|woff|woff2)$/, loader: 'file-loader?name=http://localhost:8080/fonts/[name].[ext]' }
        ]
    },
    devServer: {
        hot: true,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
            "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
        }
    }
});

1 个答案:

答案 0 :(得分:1)

出于某种奇怪的原因,我似乎已通过删除node_modules文件夹和yarn.lock文件并再次运行yarn install来解决问题。