Skip to content

Add "include" and "exclude" option to @vitejs/plugin-react-swc #486

Description

@fabian-hiller

Related plugins

Description

I want to use SolidJS inside of a React app. With @vitejs/plugin-react I can simply exclude all files that end with *.solid.tsx.

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import solid from "vite-plugin-solid";

export default defineConfig({
  plugins: [
    react({ exclude: "./src/**/*.solid.tsx" }),
    solid({ include: "./src/**/*.solid.tsx" }),
  ],
});

Is this somehow also possible with @vitejs/plugin-react-swc? Here is an example playground using @vitejs/plugin-react.

https://stackblitz.com/edit/vitejs-vite-uteimcxq?file=src%2Freact-app.tsx,src%2Fsolid-app.solid.tsx,vite.config.ts

Suggested solution

Add "include" and "exclude" option to @vitejs/plugin-react-swc

Alternative

No response

Additional context

No response

Validations

Activity

  1. ArnaudBarre commented on May 30, 2025

    @ArnaudBarre
    Member

    Yes we should add this for parity. Is there any reason apart from speed to use swc? The OXC plugin (not well tested yet) has the include/exclude options and will provide more speed when used with rolldown-vite

  2. fabian-hiller commented on May 31, 2025

    @fabian-hiller
    Author

    It's a bigger project that where already using SWC. Speed is probably the main reason. In the long run we will look into OXC.

  3. ArnaudBarre commented on Aug 30, 2025

    @ArnaudBarre
    Member

    Sorry I totally forgot about this but you can use the parserConfig option like this:

    react({
      parserConfig(id) {
        if (id.endsWith('.tsx') && !id.endsWith('.solid.tsx')) return { syntax: 'typescript', tsx: true }
        if (id.endsWith('.ts')) return { syntax: 'typescript', tsx: false }
        // all other files are ignored, so this assume you don't have JS(X) source files
      },
    })

    An include/exclude option would be better here, but it can be tricky because if we add default this could break people depending on every id being sent to this function. The current state of the SWC plugin is not rolldown friendly at all. Maybe we should do a new major once Rolldown is the default for people that require some specific SWC plugins not available on OXC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions