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.vueIf the addon author wants the addon to be globally mounted immediately when used, they can place the content invalaxy-addon-<name>/App.vueand setglobal: trueinpackage.json.components: Components placed in thecomponentsfolder 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 addonUsing 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.
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.