rspack-vue-loader is the official Rspack loader for processing Vue Single-File Components (SFCs), enabling developers to leverage Vue's component authoring format within an Rspack build pipeline. As of version `17.5.0`, it focuses exclusively on Rspack compatibility, explicitly removing dependencies on Webpack. The library is actively maintained with frequent fixes and contributions, demonstrating a stable yet evolving release cadence. Key features include the ability to apply other Rspack loaders to individual SFC blocks (e.g., Sass for <style>, Pug for <template>), support for custom blocks, automatic handling of static assets referenced in templates and styles as module dependencies, simulated scoped CSS, and state-preserving hot-reloading for an efficient development experience. It provides a dedicated and robust solution for integrating Vue.js 3 with Rspack, differentiating itself from its Webpack counterpart, `vue-loader`.
npm install rspack-vue-loaderVerified import paths — ran on the pinned version, not inferred.
This Rspack configuration demonstrates how to set up `rspack-vue-loader` for Vue 3 Single-File Components, including TypeScript support via Rspack's built-in SWC loader, and basic asset handling. It highlights the use of `VueLoaderPlugin` and the loader string in module rules.
Ensure your project uses Rspack (version 1.0.0 or 2.0.0-0, as per peer dependencies) for bundling. If you are using Webpack, use `vue-loader` instead.
Replace `refSugar: true` with `reactivityTransform: true` in your `rspack-vue-loader` options if you wish to use Vue's reactivity transform feature.
In `rspack.config.js` (or `.ts`), ensure your rule for `.vue` files uses `loader: 'rspack-vue-loader'`, not `loader: 'vue-loader'`.
Consider using `builtin:swc-loader` (Rspack's default recommendation) or `esbuild-loader` for TypeScript transpilation instead of `ts-loader` to improve HMR stability. If sticking with `ts-loader` and experiencing issues, you might set `enableTsInTemplate: false` in `rspack-vue-loader` options and avoid TS expressions in templates.
Carefully manage the `customElement` option. Use the default regex for specific custom element files, or explicitly provide a more precise `RegExp` if needed. Only set `customElement: true` if you intend for all `.vue` files to be treated as custom elements.
When using CSS preprocessors (e.g., Less, Sass), ensure you have the corresponding loaders configured (e.g., `less-loader`, `sass-loader`) and set `type: 'css'` or a chain with `vue-style-loader` if needed. For specific CSS Module behavior or when encountering issues, consult Rspack documentation on `experiments.css` and `vue-loader`'s CSS processing.
Install `@rspack/core` in your project: `npm install @rspack/core` or `pnpm install @rspack/core` or `yarn add @rspack/core`.
Add a rule to your `rspack.config.js` (or `.ts`) for `.vue` files, specifying `loader: 'rspack-vue-loader'`. Also ensure `new VueLoaderPlugin()` is in your `plugins` array.
Ensure you have `import { VueLoaderPlugin } from 'rspack-vue-loader';` at the top of your Rspack config file and `new VueLoaderPlugin()` in the `plugins` array.Ensure your CSS preprocessor loaders are compatible with Rspack. If encountering this, try configuring `experiments: { css: false }` in your Rspack config and explicitly using `vue-style-loader` and `css-loader` in your rules for `css` or preprocessor files within `.vue` components.