Skip to content

@vitejs/plugin-react processing excluded files #24

@sibbng

Description

@sibbng

Describe the bug

@vitejs/plugin-react processing files that defined in exclude option.

export default defineConfig({
  plugins: [
    react({
      exclude: /App/,
    }),
  ],
});

I was expecting @vitejs/plugin-react to bypass processing matching files and throw an error but it's still processing those files.

include and exclude filters are only checked when loading react-refresh plugin and jsx transforms are still processes for all jsx files:
https://github.com/vitejs/vite/blob/e8c840abd2767445a5e49bab6540a66b941d7239/packages/plugin-react/src/index.ts#L170

In my opinion we should do that on top of transform function by adding this:

async transform(code, id, options) {
  if (!filter(id)) {
    return
  }
  // ...  

Why I do this?

I'm currently using Solid and React on same project and both of them have their own jsx transform. I need to prevent them processing the same file. I have naming convention in my app .react.tsx for React components and .solid.tsx for Solid components. I didn't include Solid in my repro because vite-plugin-solid doesn't have an option to exclude files but I patched their plugin locally and will make a feature request on their repo.

Reproduction

https://stackblitz.com/edit/vitejs-vite-k286cf?file=vite.config.js&terminal=dev

System Info

System:
    OS: Windows 10 10.0.19042
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions