如何运行 Webpack Dev Server --https --hot --inline [英] How to run 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 overhttp
and nothttps
.
<小时>
存在一种解决方法,但非常烦人.
A workaround exists, but its very annoying.
- 在您的
index.html
中手动包含 https
webpack-dev-server
<script src="https://localhost:8080/webpack-dev-server.js"></script>
- 配置每个端点以包含
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屋!