项目运行时一直发http://localhost:8080/sockjs-node/info?t=1462183700002请求

server是webpack创建的,运行在localhost:8080,部署到服务器后运行就报错
图片描述

webpack.config.js如下

var path = require('path');
var merge = require('webpack-merge');
var webpack = require('webpack');
var TARGET = process.env.TARGET || 'dev';
var ROOT_PATH = path.resolve(__dirname);
var HtmlWebpackPlugin = require('html-webpack-plugin');

var common = {
    entry: [path.resolve(ROOT_PATH, 'app/index')],

    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    output: {
        path: path.resolve(ROOT_PATH, 'build/js'),
        filename: '/bundle.js'
    },

    plugins: [
        new HtmlWebpackPlugin({
            title: '测试',
        })

    ],

    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                loaders: ['babel'],
                include: path.resolve(ROOT_PATH, 'app')
            },

            {
                test: /\.css$/,
                loaders: ['style', 'css']
            }
        ]
    }
};
switch (TARGET) {
    case 'build':
        module.exports = merge(common, {
            plugins: [
                new webpack.optimize.UglifyJsPlugin({
                    compress: {
                        warnings: false
                    }
                }),
                new webpack.DefinePlugin({
                    'process.env': {
                        'NODE_ENV': JSON.stringify('production')
                    }
                })
            ]
        });

        break;

    case 'dev':
        module.exports = merge(common, {
            entry: [
                'webpack-dev-server/client?http://localhost:8080',
                'webpack/hot/dev-server'
            ]
        });
        break;
}
阅读 66.2k
评论
    18 个回答

    如果你的浏览器,与NPM服务器,不是同一个机器(不是localhost),那么会导致这个报错。

    我搜索了好久,才发现这个是可以在webpackjs里配置的(即vue.config.js):
    https://webpack.js.org/config...

    module.exports = {
        devServer: {
            sockHost: 'demo.my-domain.com',
            disableHostCheck: true,
        }
    }