Writing a Plugin

A plugin should export a plain JavaScript object(#1). If the plugin needs to take options, it can be a function that returns a plain object(#2). The function will be called with the plugin’s options as the first argument, along with ctx which provides some compile-time metadata.

  1. // #1
  2. module.exports = {
  3. // ...
  4. }
  1. // #2
  2. module.exports = (options, ctx) => {
  3. return {
  4. // ...
  5. }
  6. }

TIP

A VuePress plugin module should be a CommonJS Module because VuePress plugins runs on the Node.js side.