Write an Addon

Getting Started

TIP

Convention over Configuration

  • Addon: Must start with valaxy-addon-.
  • Addons are similar to themes, but do less.
  • A site can only use one theme, but can use multiple addons.
  • Addons do not need to be precompiled, just publish the source files directly.
  • App.vue If the addon author wants the addon to be globally mounted immediately when used, they can place the content in valaxy-addon-<name>/App.vue and set global: true in package.json.
  • components: Components placed in the components folder will be automatically registered, but not mounted. Users can manually load and use them.

Documentation is under construction. You can refer to some existing addons in the Addon Gallery.

Create Addon Template

bash
pnpm create valaxy
# choose template addon

Using Lifecycle Hooks

As shown in the example, addons can use valaxy.hook to mount lifecycle hooks. This allows you to do things before/after the build and at other points.

Please refer to Lifecycle Hooks for more information.

valaxy-addon-test/node/index.ts
ts
import { consola } from 'consola'
import { defineValaxyAddon } from 'valaxy'
import pkg from '../package.json'

export const addonTest = defineValaxyAddon(options => ({
  name: pkg.name,
  enable: true,
  options,

  setup(valaxy) {
    valaxy.hook('build:before', () => {
      // do something before build
      consola.info('[valaxy-addon-test] build:before')
    })
  },
}))

To Be Continued.

Contributors