如何运行 Webpack Dev Server --https --hot --inline [英] How to run Webpack Dev Server --https --hot --inline

查看:24
本文介绍了如何运行 Webpack Dev Server --https --hot --inline的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 CLI 进行配置时,是否可以利用在 https 上运行 webpack-dev-server 的方法?

Is there a way to leverage running the webpack-dev-server on https when configuring using CLI?

问题是与 socket.io 的连接是通过 http 而不是 https.

The problem is the connection to socket.io is over http and not https.

<小时>

存在一种解决方法,但非常烦人.


A workaround exists, but its very annoying.

  1. 在您的 index.html
  2. 中手动包含 https webpack-dev-server

<script src="https://localhost:8080/webpack-dev-server.js"></script>

  1. 配置每个端点以包含 webpack/hot/only-dev-server.

app: [
    'webpack/hot/only-dev-server',
    './app.js'
],

// ... more entry points that include the same [] ...

推荐答案

是的,当使用 CLI 进行配置时,有一种方法可以在 https 上配置 webpack-dev-server.

Yes there is a way to configure webpack-dev-server on https when configuring using CLI.

解决方案是不使用 --inline 选项.

The solution is to not use --inline option.

配置服务器和--hot的方法有很多.假设您没有创建自定义服务器实现/中间件(可能相同),接下来的内容在文档中有详细说明.

There are many ways to configure the server and --hot. The one to follow, assuming your not creating a custom server implementation/middleware (Might be the same), is detailed in the docs.

http://webpack.github.io/docs/webpack-dev-server.html#webpack-dev-server-cli

  • 不要包含<script src="https://localhost:8080/webpack-dev-server.js"></script>
  • 请勿在条目中包含 webpack/hot/only-dev-server.
  • Do not include <script src="https://localhost:8080/webpack-dev-server.js"></script>
  • Do not include webpack/hot/only-dev-server into the entry.
{
  "scripts": {
    "start": "webpack-dev-server -d --hot --https --config webpack.config.development.js"
  }
}

webpack.config.development.js

var webpackConfig = require('webpack-config');

module.exports = webpackConfig.fromCwd().merge({
    devServer: {
        colors:             true,
        contentBase:        './build',
        historyApiFallback: true,
        inline:             true,
        progress:           true
    },

    devtool: 'eval-source-map'
});

此处未列出主要的 webpack 配置.

这篇关于如何运行 Webpack Dev Server --https --hot --inline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆