{"id":19097317,"url":"https://github.com/vite-plugin/vite-plugin-lang-jsx","last_synced_at":"2025-04-30T14:30:00.221Z","repository":{"id":45659318,"uuid":"501867382","full_name":"vite-plugin/vite-plugin-lang-jsx","owner":"vite-plugin","description":"Support write jsx in js files","archived":false,"fork":false,"pushed_at":"2023-10-19T06:54:20.000Z","size":49,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-30T14:29:54.457Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vite-plugin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-06-10T01:57:17.000Z","updated_at":"2025-01-17T03:26:05.000Z","dependencies_parsed_at":"2023-10-19T08:45:09.199Z","dependency_job_id":null,"html_url":"https://github.com/vite-plugin/vite-plugin-lang-jsx","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.3928571428571429,"last_synced_commit":"0cc4cf45537ce746bfa0ff672fc69265803f5d3b"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vite-plugin%2Fvite-plugin-lang-jsx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vite-plugin%2Fvite-plugin-lang-jsx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vite-plugin%2Fvite-plugin-lang-jsx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vite-plugin%2Fvite-plugin-lang-jsx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vite-plugin","download_url":"https://codeload.github.com/vite-plugin/vite-plugin-lang-jsx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251721335,"owners_count":21632814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T03:39:56.708Z","updated_at":"2025-04-30T14:30:00.202Z","avatar_url":"https://github.com/vite-plugin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vite-plugin-lang-jsx\n\nSupport write jsx in js files\n\n[![npm package](https://nodei.co/npm/vite-plugin-lang-jsx.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://www.npmjs.com/package/vite-plugin-lang-jsx)\n[![NPM version](https://img.shields.io/npm/v/vite-plugin-lang-jsx.svg)](https://npmjs.org/package/vite-plugin-lang-jsx)\n[![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-lang-jsx.svg)](https://npmjs.org/package/vite-plugin-lang-jsx)\n\nEnglish | [简体中文](https://github.com/vite-plugin/vite-plugin-lang-jsx/blob/main/README.zh-CN.md)\n\n✅ Support write `jsx` in `.vue` files  \n✅ Compatible `create-react-app`  \n\n## Install\n\n```sh\nnpm i vite-plugin-lang-jsx -D\n```\n\n## Usage\n\n#### Vue2 Project\n\nAutomatically add `lang=\"jsx\"` to `\u003cscript\u003e` tag when using `vite-plugin-vue2`\n\n🚧 The plugin should be placed before `vite-plugin-vue2`\n\n```js\nimport langJsx from 'vite-plugin-lang-jsx'\nimport { createVuePlugin } from 'vite-plugin-vue2'\n\nexport default {\n  plugins: [\n    langJsx(/* options */),\n    createVuePlugin(),\n  ]\n}\n```\n\n#### create-react-app\n\n```js\nimport langJsx from 'vite-plugin-lang-jsx'\n\nexport default {\n  plugins: [\n    langJsx(),\n    // ...other plugins\n  ]\n}\n```\n\n## API \u003csub\u003e\u003csup\u003e(Define)\u003c/sup\u003e\u003c/sub\u003e\n\n```ts\nexport interface LangJsx {\n  (options?: {\n    filter?: (id: string) =\u003e boolean | void;\n    /**\n     * Check JSX with ast, and use RegExp by default.\n     */\n    useAst?: boolean;\n  }): Plugin[];\n}\n```\n\n## How to work\n\n`.vue` files\n\n```html\n// source code\n\u003cscript\u003e\n  export default {\n    render() {\n      return \u003cdiv\u003eHello world!\u003c/div\u003e;\n    },\n  }\n\u003c/script\u003e\n\n// transformed\n\u003cscript lang=\"jsx\"\u003e\n  export default {\n    render() {\n      return \u003cdiv\u003eHello world!\u003c/div\u003e;\n    },\n  }\n\u003c/script\u003e\n\n```\n\n`.js` files\n\n```js\n// source code\nimport JsxComponent from './jsx-component'\n\n// add `lang.jsx` suffix\nimport JsxComponent from './jsx-component?lang.jsx'\n\n```\n\n## Why\n\nWhile we upgrade the Vue2.x proejct created by `@vue/cli` to Vite, we will use `vue-plugin-vue2`.\n\n1. However, `vue-plugin-vue2` does not automatically handle the `jsx` syntax in `\u003cscript\u003e`. So we need to add `lang=jsx` above `\u003cscript\u003e` to ensure its worked.\n\n2. Secondly, the plugin allows you to write `jsx` syntax in the `.js` file.  \n\nMany times many prople like to write `jsx` in the `.js` file in the React project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvite-plugin%2Fvite-plugin-lang-jsx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvite-plugin%2Fvite-plugin-lang-jsx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvite-plugin%2Fvite-plugin-lang-jsx/lists"}