Svelte plugin
The Svelte plugin provides support for Svelte components (.svelte files). The plugin internally integrates svelte-loader.
Quick start
Install plugin
Run the following command:
@rsbuild/plugin-svelte v2 no longer supports Rsbuild 1.x or Svelte 4.x. If your project uses these versions, install @rsbuild/plugin-svelte@1 instead.
Register plugin
Register the plugin in Rsbuild config:
After registration, you can import *.svelte files in your code.
Options
To customize the compilation behavior of Svelte, use the following options.
svelteLoaderOptions
These options are passed to svelte-loader. For details, see the svelte-loader documentation.
- Type:
SvelteLoaderOptions - Default:
- Example:
preprocessOptions
These options are passed to svelte-preprocess. For details, see the svelte-preprocess documentation.
- Type:
AutoPreprocessOptions - Default:
undefined
- Example:
Notes
Currently, svelte-loader does not support HMR for Svelte v5, see svelte-loader - Hot Reload.
Alias handling in Less/Sass
Svelte preprocessors do not automatically use Rsbuild's path aliases. To use @/ in style imports, configure a Sass importer or a Less plugin.
The following example maps @/ to the src directory next to the configuration file. It supports imports such as @use '@/styles/variables.scss' as * in SCSS and @import '@/styles/variables.less' in Less:

