IOS设备无法加载资源:无法连接到服务器

时间:2017-11-24 14:17:06

标签: nginx webpack webpack-dev-server

  • 操作系统:OSX
  • 节点:8.4.0
  • NPM:5.3.0
  • webpack:^ 3.8.1
  • webpack-dev-server:^ 2.9.4

webpack.config.js

const join = (modulePath) => path.join(process.cwd(), modulePath);
const port = 3000;

let config = {
  entry: {
    app: join('app')
  },
  output: {
    filename: '[name].js',
    path: join('dist'),
    pathinfo: true,
    publicPath: `http://localhost:${port}`
  },
  devServer: {
    contentBase: './app',
    historyApiFallback: true,
    inline: true,
    port,
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules)/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: ['es2015'],
            }
          }
        ]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(['dist', 'build'], {
      root: process.cwd()
    }),
    new HtmlWebpackPlugin({
      template: 'app/index.html',
      filename: 'index.html'
    })
  ]
};

module.exports = config;

nginx反向代理配置

server {
        listen 80;
        server_name  www.domain1.com;
        error_page 500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location /srilanka/ {
            proxy_pass http://localhost:3000/;
        }
    }

主机

127.0.0.1 www.domain1.com

我使用nginx反向代理+ webpack-dev-server

对于IOS设备,它会抛出错误:

Failed to load resource: Could not connect to the server http://localhost:3000/app.js

PC和Android设备运行正常。

预期行为

使用IOS设备访问网站应该可以正常工作。

实际行为

我使用IOS设备safari web检查器找到此错误。

我创建了一个repo,因此您可以轻松地重现此行为 https://github.com/mrdulin/webpack-dev-server

0 个答案:

没有答案