# vuepress-plugin-serve

Serve generated files of your VuePress site locally.

# Installation

npm install -D vuepress-plugin-serve

# Usage

// .vuepress/config.js
module.exports = {
  plugins: [
    [
      'vuepress-plugin-serve',
      {
        post: 1234,
        staticOptions: {
          dotfiles: 'allow',
        },
        beforeServer(app, server) {
          app.get('/path/to/my/custom', function(req, res) {
            res.json({ custom: 'response' })
          })
        },
      },
    ],
  ],
}

# Configs

# commandName

  • type: string
  • default: 'serve'

vuepress-plugin-serve will add a vuepress command. This option can be used to specify the command name.

# host

  • type: string
  • default: siteConfig.host || 'localhost'

Specify the host to use for the server.

# port

  • type: number
  • default: siteConfig.port || 8080

Specify the port to use for the server.

# notFoundPath

  • type: string
  • default: '404.html'

Path for "404 not found" page (relative to dest path).

# staticOptions

  • type: object
  • default: {}

Options for serve-static.

# beforeServer

  • type: (app, server) => void | Promise<void>
  • default: undefined

Executed before the server accepts client information. Similar to VuePress's beforeDevServer option.

# afterServer

  • type: async (app, server) => void | Promise<void>
  • default: undefined

Executed after the server accepts client information. Similar to VuePress's afterDevServer option.

# CLI

After using this plugin, VuePress will add a serve command. This command will created a server based on the generated files. It has the following options:

# --build

Execute vuepress build before creating the server.

# --open

Open the browser when the server is ready.

# --host <host>

See host.

# --port <port>

See port.

TIP

VuePress built-in command line options (such as --dest <dest>, --cache [cache], --no-cache) are also supported.