@macroforge/svelte-preprocessor
v0.1.75
Published
Svelte preprocessor for expanding Macroforge macros in component script blocks
Maintainers
Readme
@macroforge/svelte-preprocessor
Svelte preprocessor for expanding Macroforge macros in component script blocks
Overview
@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.
How It Works
- 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
Important Notes
- 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)
Installation
npm install @macroforge/svelte-preprocessorAPI
Functions
macroforgePreprocess- Whether to preserve@derivedecorators in the expanded output.
Types
ExpandResult- Whether to preserve@derivedecorators in the expanded output.MacroforgePreprocessorOptions- Configuration options for the Macroforge Svelte preprocessor.
Examples
macroforgePreprocess();
macroforgePreprocess({ keepDecorators: true });
macroforgePreprocess({ processJavaScript: true });Documentation
See the full documentation on the Macroforge website.
License
MIT
