unimal-jp / spear

The spear OSS repository
https://late-cloud-6411.spearly.app
MIT License
10 stars 1 forks source link

Proposal: Hook API #70

Closed mantaroh closed 1 year ago

mantaroh commented 1 year ago

What is this?

This Hook API is inspired from Astro API
This API allows to hook each step of build.
For example:

If we provide injection of some static file after building, this API might be helpful.

Why do we need this API?

This API help for third-party developer who developing plugins:

Specifications

Way to inject hook API

We provide hook API function type.

export interface HookApi {
    configuration?: ConfigurationHookFunction,
    beforeBuild?: BeforeBuildHookFunction,
    afterBuild? : AfterBuildHookFunction,
    bundle? : BundleHookFunction,
}
property function parameter describe return value
configuration SpearSettings Call when configuration process has complete. Settings if change the setting value
beforeBuild SpearState Call before build process starting SpearState if change this state value
afterBuild SpearState Call after building process has finished.(This mean before bundling) SpearState if you want to change this value
bundle SpearState Call before after bundle process.

User specify this hook function into spear.config.js .

sample: spear.config.mjs

import  { hookSample } from "./hook-sample.js"
{
  "plugins": [
     hookSample,
  ]
}
mantaroh commented 1 year ago

114 related work

mantaroh commented 1 year ago

https://github.com/unimal-jp/spear-doc/issues/4