简体   繁体   English

VuePress:如何在开发服务器中使用 https?

[英]VuePress: How can I use https in dev server?

Is there any hook to enable https in VuePress dev server?在 VuePress 开发服务器中启用 https 是否有任何挂钩?

1. Current solution. 1. 当前解决方案。

I directly add one line to node_modules/@vuepress/core/lib/node/dev/index.js .我直接在node_modules/@vuepress/core/lib/node/dev/index.js添加一行。 This works well, but nasty.这很好用,但很讨厌。

  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. Background 2. 背景

Because Chrome has changed it's security policy, CORS.因为 Chrome 更改了它的安全策略,CORS。

图片:“将跨站点 cookie 标记为安全,以允许它们在跨站点请求中发送。”

3. What I've tried. 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. Related links. 4.相关链接。

Add the following settings to config.js .将以下设置添加到config.js

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

  devServer: {
    https: true
  },

}

Thank you for your guidance in many ways.感谢您多方面的指导。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM