Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions website/docs/en/plugins/list/plugin-svelte.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,39 @@ pluginSvelte({
## Notes

Currently, `svelte-loader` does not support HMR for Svelte v5, see [svelte-loader - Hot Reload](https://github.com/sveltejs/svelte-loader?tab=readme-ov-file#hot-reload).

### Alias handling in LESS/SCSS
Comment thread
chenjiahan marked this conversation as resolved.
Outdated

When using aliases to import Less or SCSS files within Svelte components, you need to manually configure the preprocessor to handle alias resolution. Otherwise, you may encounter `"file not found"` errors.
Comment thread
chenjiahan marked this conversation as resolved.
Outdated

**Example:**
Comment thread
chenjiahan marked this conversation as resolved.
Outdated

```ts title="rsbuild.config.ts"
import { pluginSvelte } from '@rsbuild/plugin-svelte';

export default {
plugins: [
pluginSvelte({
preprocessOptions: {
scss: {
importer: [
// Handle alias imports for SCSS files
(url, prev) => {
if (url.startsWith('@/')) {
return { file: url.replace('@/', 'src/') };
}
return null;
},
],
},
less: {
// use less preprocessing to handle alias imports
Comment thread
GRAMMAC1 marked this conversation as resolved.
plugins: [],
},
},
}),
],
};
```

This ensures that alias imports like `@import '@/styles/variables.scss'` or `@import '@/styles/variables.less'` are properly resolved within Svelte components.
36 changes: 36 additions & 0 deletions website/docs/zh/plugins/list/plugin-svelte.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,39 @@ pluginSvelte({
## 注意事项

目前 `svelte-loader` 暂不支持 Svelte v5 热更新,详见 [svelte-loader - Hot Reload](https://github.com/sveltejs/svelte-loader?tab=readme-ov-file#hot-reload)。

### LESS/SCSS 中的别名处理
Comment thread
chenjiahan marked this conversation as resolved.
Outdated

在 Svelte 组件中使用别名引入 LESS/SCSS 文件时,需要手动处理别名的路径解析,否则会出现 `"file not found"` 的错误。
Comment thread
chenjiahan marked this conversation as resolved.
Outdated

**示例:**
Comment thread
chenjiahan marked this conversation as resolved.
Outdated

```ts title="rsbuild.config.ts"
import { pluginSvelte } from '@rsbuild/plugin-svelte';

export default {
plugins: [
pluginSvelte({
preprocessOptions: {
scss: {
importer: [
// 处理 SCSS 文件的别名导入
(url, prev) => {
if (url.startsWith('@/')) {
return { file: url.replace('@/', 'src/') };
}
return null;
},
],
},
less: {
// 使用 less preprocessing 来处理别名导入
plugins: [],
},
},
}),
],
};
```

通过配置 `preprocessOptions` 可以保证在 Svelte 组件中引入的 `@import '@/styles/variables.scss` 或者 `@import '@/styles/variables.less'` 能够正确解析。
Comment thread
chenjiahan marked this conversation as resolved.
Outdated
Loading