preprocess() function provides hooks for transforming component source code before compilation. Use it to add support for TypeScript, PostCSS, SCSS, and other preprocessors.
Signature
Parameters
The component source code to preprocess
A preprocessor group or array of preprocessor groups. Each group can have
markup, script, and style hooks.The filename of the component (used for debugging and source maps)
Return Value
Returns aPromise<Processed> with:
The transformed source code
A source map mapping back to the original code
Array of additional files to watch for changes
Preprocessor Hooks
markup
Processes the entire component source.script
Processes the content of<script> tags.
style
Processes the content of<style> tags.
Same signature as
script preprocessorProcessed Return Type
Each preprocessor hook can return:The transformed code
A source map
Files to watch for changes
(script/style only) Updated attributes for the tag
Usage Examples
TypeScript Preprocessor
SCSS Preprocessor
Multiple Preprocessors
Markup Preprocessor
Using svelte-preprocess
With Vite
Watching Dependencies
Related
- compile() - Compile preprocessed source
- Compiler Options - Compiler configuration