Writing a Plugin
Before reading this guide, you’d better learn the VuePress architecture first.
A VuePress plugin is a plain JavaScript object that satisfies the , which is called a Plugin Object.
- Plugin Object
- Plugin Function
return {
name: 'vuepress-plugin-foo',
}
}
Publish to NPM
The typical structure of a plugin package is as follow:
The lib/index.js
file is the plugin entry, which should export the plugin directly:
- CJS
- ESM
module.export = fooPlugin
Notice that the plugin entry will be loaded in Node, so it should be in CommonJS format.
If you are using ESM format, you’ll need to use or typescriptopen in new window to transpile it into CommonJS.
package.json
{
"version": "1.0.0",
"keywords": [
],
"main": "lib/index.js",
"files": [
"lib"
]
- Set
name
to follow the naming convention:vuepress-plugin-xxx
or@org/vuepress-plugin-xxx
. - Set
keywords
to includevuepress-plugin
, so that users can search your plugin on NPM. - Set
main
to the plugin entry file.