Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@vitejs/plugin-react can support more extensions #22

Closed
4 tasks done
LaamGinghong opened this issue Mar 7, 2022 · 7 comments · Fixed by #122
Closed
4 tasks done

@vitejs/plugin-react can support more extensions #22

LaamGinghong opened this issue Mar 7, 2022 · 7 comments · Fixed by #122
Labels
enhancement New feature or request

Comments

@LaamGinghong
Copy link

Clear and concise description of the problem

I'm doing markdown conversion to React component. However, this plugin may only be supported .jsx? or .tsx? file. So I had to use an extra Babel plugin to handle the files generated by the markdown transformation.

Suggested solution

Add a configuration extension to the plugin's options and support any text that conforms to React component.

Alternative

No response

Additional context

No response

Validations

@Niputi
Copy link
Contributor

Niputi commented Mar 7, 2022

please give more details.
what exactly are you trying to do and how do you expect it to work

@LaamGinghong
Copy link
Author

@Niputi
I wrote a Vite plugin to transform markdown to React component. The output of the plugin looks something like this:

export default () => <div> {/* The transformed code */}</div>

However, @vitejs/plugin-react could not accept a .md file and I had to use babel to transform the jsx to js.

This is my current configuration file:

plugins: [
  vitePluginDocs(), // my markdown transform plugin
  babel({
    extensions: ['.md'],
    configFile: false,
    presets: [['@babel/preset-react', { runtime: 'automatic' }]],
    babelHelpers: 'bundled'
  })
  viteReact()
]

I want the @vitejs/plugin-react to accept an extra parameter to accept more file's format like this:

plugins: [
  vitePluginDocs(), // my markdown transform plugin
  viteReact({ extensions: ['.tsx', '.md'], })
]

So I can remove the babel from my config.

@LaamGinghong
Copy link
Author

By reading the plugin's code, I found that the plugin will only convert mjs | js | jsx | ts | tsx file

@bluwy
Copy link
Member

bluwy commented Mar 8, 2022

vite-plugin-svelte has a similar feature too that allows specifying the extensions. Probably worth nothing a caveat though: sveltejs/vite-plugin-svelte#60

@LaamGinghong
Copy link
Author

@bluwy I think it's a nice feature, so what do you think?

@bluwy
Copy link
Member

bluwy commented Mar 9, 2022

I'm not familiar with React (nor the vite plugin) so I can't say for sure if there are caveats to this. @aleclarson might know more about it.

@patak-dev patak-dev transferred this issue from vitejs/vite Dec 3, 2022
@sapphi-red sapphi-red added the enhancement New feature or request label Dec 19, 2022
@ArnaudBarre
Copy link
Member

ArnaudBarre commented Jan 22, 2023

Hi!
Yes that's a limitation of the current API. Making this change non breaking would make the API unusable so I plan to change this in the next major with #53, hopefully in less than one month

@github-actions github-actions bot locked and limited conversation to collaborators Apr 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
5 participants