Search code examples
httpsvuepress

VuePress: How can I use https in dev server?


Is there any hook to enable https in VuePress dev server?

1. Current solution.

I directly add one line to 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

Because Chrome has changed it's security policy, CORS.

Image: "Mark cross-site cookies as Secure to allow them to be sent in cross-site requests."

3. What I've tried.

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.


Solution

  • Add the following settings to config.js.

    //
    // docs/.vuepress/config.js
    //
    module.exports = {
    
      devServer: {
        https: true
      },
    
    }
    

    Thank you for your guidance in many ways.