将webpack-serve配置为允许通过SSL进行热模块重载(HMR)的正确方法是什么?我可以通过HTTPS毫无问题地访问提供的内容,但是无法建立用于HMR的websocket连接。这是我在页面加载后在Firefox控制台中看到的内容:
Firefox can’t establish a connection to the server at wss://local.jonmorton.me:5444/.
这似乎表明正在使用配置的协议(wss)和端口(5444)。但是,我无法从文档中辨别出我还缺少什么。
这是我的配置的相关部分:
const HOST = process.env.HOST
...
let options = {
...
serve: {
host: HOST,
port: 5443,
https: {
key: fs.readFileSync(HOST + '.key'),
cert: fs.readFileSync(HOST + '.cert')
},
hot: {
host: HOST,
port: 5444,
https: true
}
}
我有理由相信其余配置是正确的,但是为了完整起见,我将其包括在内。
const fs = require('fs');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MODE = process.env.WEBPACK_SERVE ? 'development' : 'production';
const HOST = process.env.HOST || 'localhost';
let options = {
mode: MODE,
entry: './src/main.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'build.js'
},
plugins: [
new HtmlWebpackPlugin({ template: './src/templates/index.html',
filename: 'index.html' })
],
module: {
rules: [
{ test: /\.js$/,
exclude: /node_modules/,
use: [{loader: 'babel-loader',
options: { presets: ['babel-preset-env'] }}]},
{ test: /\.(scss|sass)$/,
use: [{loader: 'style-loader' },
{loader: 'css-loader' },
{loader: 'sass-loader' }]}]
},
serve: {
host: HOST,
port: 5443,
https: {
key: fs.readFileSync(HOST + '.key'),
cert: fs.readFileSync(HOST + '.cert')
},
hot: {
host: HOST,
port: 5444,
https: true
}
}
};
module.exports = options;
一些其他背景:
Upgrade Required