Vue + Webpack——指定服务器热重载

Vue + Webpack - Specifying the server for hot reload

所以我有以下用于 webpack-dev-server 的配置文件:

'use strict'
const { VueLoaderPlugin } = require('vue-loader');
const HtmlWebpackPlugin = require('html-webpack-plugin');


module.exports = {
    mode: 'development',
    entry: [
        './src/app.js'
    ],
    module: {
        rules: [
            {
                test: /\.vue$/,
                use: 'vue-loader'
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: 'index.html',
            inject: true
        })
    ],
}

一切正常,但默认情况下它似乎在 http://localhost:8082. Is there a way to specify what host to use for the live reload, like say i have a custom domain defined as https://hotreload.com:3000 上启动实时重新加载服务器?如有任何帮助,我们将不胜感激!

编辑您的 webpack.config.js 以指定 devServer.host, devServer.port, and devServer.https。使用您的示例规范:

module.exports = {
  //...
  devServer: {
    host: 'hotreload.com',
    port: 3000,
    https: true,
  }
}

您必须设置 devServer.public。如果这只采用 url 路径就好了,但它显然需要整个 url:

devServer: {
    public: 'https://www.yoursite.com/',
}