【问题标题】:How can remove the port number from live vue site url?如何从实时 vue 站点 url 中删除端口号?
【发布时间】:2021-11-20 11:06:20
【问题描述】:

在运行yarn serve 时,我没有从 URL 中显示端口号。现在,这显示为https://example.com:8080。我想从https://example.com 访问它们。

vue.config.js

module.exports = {
    chainWebpack: config => {
      config.plugins.delete('prefetch');
    },
    devServer: {
        host: 'example.com',
        https: false,
        port: 8080, 
        public: 'example.com'
    }, 
}

【问题讨论】:

    标签: vue.js vue-component port javascript-framework


    【解决方案1】:

    用live server打开dist文件夹中的index.html

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案2】:

    yarn serve 命令打开此端口以在本地为应用程序提供服务(用于测试/开发)。

    如果您想创建应用程序,您可能需要运行:
    yarn run build

    SO - yarn build command

    然后您可以上传生成的文件。查找builddist 目录或类似目录。

    您可以将publicPath 添加到您的配置中:

    module.exports = {
        publicPath: "./",
        chainWebpack: config => {
          config.plugins.delete('prefetch');
        },
        devServer: {
            host: 'example.com',
            https: false,
            port: 8080, 
            public: 'example.com'
        }, 
    }
    

    你可以试试这个,看看它是否有效。

    webpack configuration docs

    【讨论】:

    猜你喜欢
    • 2020-03-02
    • 2016-02-06
    • 2014-12-18
    • 2014-07-18
    • 2011-07-04
    • 2015-08-17
    • 2021-10-24
    相关资源
    最近更新 更多