Svelte preprocessor for expanding Macroforge macros in component script blocks
@macroforge/svelte-preprocessor
Svelte preprocessor for expanding Macroforge macros in component script blocks.
This module provides integration between Macroforge's macro expansion system and
Svelte's preprocessing pipeline. It intercepts <script> blocks in .svelte files,
detects @derive decorators, and expands them into generated code before TypeScript
compilation occurs.
- The preprocessor is registered in
svelte.config.jsas part of the preprocess array - When Svelte compiles a component, it passes each
<script>block to this preprocessor - The preprocessor checks if the script contains
@derivedecorators - If found, it calls the native
macroforgebinding to expand the macros - The expanded code replaces the original script content
- Must be placed BEFORE other preprocessors (like
vitePreprocess()) in the chain - Uses lazy-loading for native bindings to avoid initialization overhead
- Gracefully degrades if native bindings are unavailable
- Only processes TypeScript blocks by default (configurable via options)
npm install @macroforge/svelte-preprocessormacroforgePreprocess- Whether to preserve@derivedecorators in the expanded output.
ExpandResult- Whether to preserve@derivedecorators in the expanded output.MacroforgePreprocessorOptions- Configuration options for the Macroforge Svelte preprocessor.
macroforgePreprocess()
macroforgePreprocess({ keepDecorators: true })
macroforgePreprocess({ processJavaScript: true })See the full documentation on the Macroforge website.
MIT