【问题标题】:VuePress: How can I use https in dev server?VuePress:如何在开发服务器中使用 https?
【发布时间】:2020-11-08 15:11:51
【问题描述】:

在 VuePress 开发服务器中启用 https 有什么钩子吗?

1。当前解决方案。

我直接给node_modules/@vuepress/core/lib/node/dev/index.js加了一行。这很好用,但很讨厌。

  createServer () {
    const contentBase = path.resolve(this.context.sourceDir, '.vuepress/public')

    const serverConfig = Object.assign({

      https: true, // <--- Added this line.

      disableHostCheck: true,
      compress: true,
      clientLogLevel: 'error',

2。背景

因为 Chrome 改变了它的安全策略,CORS。

3。我试过了。

docs/.vuepress/config.js

  configureWebpack: (config, isServer) => {
    if (!config.devServer) {
      config.devServer = {}
    }
    Object.assign(config.devServer, {
      https: true,
    })
  }
module.exports = function (cli, options) {
  cli
    .command(`dev [targetDir]`, 'start development server')
    .option('-p, --port <port>', 'use specified port (default: 8080)')
    .option('-t, --temp <temp>', 'set the directory of the temporary file')
    .option('-c, --cache [cache]', 'set the directory of cache')
    .option('--host <host>', 'use specified host (default: 0.0.0.0)')
    .option('--no-cache', 'clean the cache before build')
    .option('--no-clear-screen', 'do not clear screen when dev server is ready')
    .option('--debug', 'start development server in debug mode')
    .option('--silent', 'start development server in silent mode')
    .option('--open', 'open browser when ready')
    .action((sourceDir = '.', commandOptions) => {
      const { debug, silent } = commandOptions

4。相关链接。

【问题讨论】:

  • 欢迎来到 StackOverflow 社区!似乎您已尝试自己格式化问题,这是..至少您尝试过。只需阅读这篇文章(stackoverflow.com/editing-help),它将帮助您将来处理 Markdown。并且不要忘记为提供有关您问题的有用信息的用户投票并将其标记为已解决。
  • 复制一下,先生 :)
  • 检查这个问题,会帮助你:stackoverflow.com/questions/45807049/…
  • Gabriel Willemann,感谢您的指导。

标签: https vuepress


【解决方案1】:

将以下设置添加到config.js

//
// docs/.vuepress/config.js
//
module.exports = {

  devServer: {
    https: true
  },

}

感谢您在很多方面的指导。

【讨论】:

    猜你喜欢
    • 2023-04-07
    • 2018-01-30
    • 1970-01-01
    • 2017-08-09
    • 2015-11-05
    • 2021-02-15
    • 2020-07-16
    • 2019-12-27
    • 2018-04-02
    相关资源
    最近更新 更多