Skip to content

Support respecting moduleType in internal plugins #350

@nia3y

Description

@nia3y

Describe the bug

i write a plugin transform markdown to jsx, the result include moduleType: 'jsx',but oxc not handle this result

minimal reproducible example

  1. markdown to jsx plugin
import type { Plugin } from 'vite';

export function mdToJsx(): Plugin {
  return {
    name: 'vite:md-to-jsx',
    transform: {
      order: 'pre',
      filter: {
        id: /\.md$/,
      },
      async handler(src: string) {
        const code = `export default function MDContent() {
                                  return <div>hello</div>
                                };`
        return {
          code,
          moduleType: 'jsx',
        };
      },
    },
  };
}
  1. config rolldown-vite with enableNativePlugin: true, resolve extensions includes .md and mdToJsx plugin
import { defineConfig } from 'vite';
import { mdToJsx } from './plugins/md-to-jsx.mjs';

export default defineConfig({
  experimental: {
    enableNativePlugin: true,
  },
  oxc: {
    include: /\.(m?ts|[jt]sx|md)$/,
  },
  resolve: {
    extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json', '.md'],
  },
  plugins: [mdToJsx()],
});

Reproduction

https://stackblitz.com/edit/vitejs-rolldown-vite-ygquhwyz?file=vite.config.mjs,plugins%2Fmd-to-jsx.mjs

Steps to reproduce

No response

System Info

System:
    OS: Linux 6.15 Manjaro Linux
    CPU: (16) x64 AMD Ryzen 9 7940HS w/ Radeon 780M Graphics
    Memory: 17.43 GB / 29.15 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 24.4.1 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 11.4.2 - /usr/bin/npm
    pnpm: 10.13.1 - /usr/bin/pnpm

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions