During the gro dev
and gro build
tasks,
Gro uses Plugin
s to support custom usecases outside of the normal build pipeline.
In this early implementation of plugins in Gro,
plugins run serially, in the order they are returned from plugins
in the gro.config.ts
.
Each step of Gro's build processes - gro dev
for development and gro build
for production -
runs a method of each plugin, batched together as setup -> adapt -> teardown
,
with some behavioral inconsistencies:
adapt
only runs during production akagro build
teardown
does not run forgro dev
in the defaultwatch
mode, but it does run withgro dev --no-watch
- there should probably be a finalization step that runs
teardown
on uncaught exceptions
The API needs to be improved for more advanced usecases,
currently it offers little flexibility -
we'll follow the Vite/SvelteKit APIs probably. (pre
etc)
Maybe let you map the array of each method batch. (is that possible with those?)
Gro's builtin plugins:
@ryanatkn/gro_plugin_server
- Node server support@ryanatkn/gro_plugin_sveltekit_library
- for publishing from$lib/
withsvelte-package
@ryanatkn/gro_plugin_sveltekit_app
- see the docs@ryanatkn/gro_plugin_gen
- watchsrc/
and efficiently rungen
when genfiles or their deps change@ryanatkn/gro_plugin_moss
- generate the optimized Moss classes file$routes/moss.css
, efficiently watchingsrc/
and the deps
TODO add docs for the above
Also see config.plugin
in the config docs
and usage in the default config.
The default config detects which plugins are included by inspecting the current project.
The implementation is at src/lib/plugin.ts
with more details.
export interface Plugin<T_Plugin_Context extends Plugin_Context = Plugin_Context> {
name: string;
setup?: (ctx: T_Plugin_Context) => void | Promise<void>;
adapt?: (ctx: T_Plugin_Context) => void | Promise<void>;
teardown?: (ctx: T_Plugin_Context) => void | Promise<void>;
}
export interface Plugin_Context<T_Args = object> extends Task_Context<T_Args> {
dev: boolean;
watch: boolean;
}
The adapt
step only runs for production during gro build
, taking after SvelteKit adapters.