Skip to content

Commit

Permalink
Merge pull request #63 from rolldown/add-oxc-jsx-include
Browse files Browse the repository at this point in the history
feat: add oxc jsxInclude and jsxExclude
  • Loading branch information
underfin authored Oct 18, 2024
2 parents f6f9fbe + 1d115b2 commit 3a82b11
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions packages/vite/src/node/plugins/oxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface OxcOptions extends OxcTransformOptions {
include?: string | RegExp | string[] | RegExp[]
exclude?: string | RegExp | string[] | RegExp[]
jsxInject?: string
jsxInclude?: string | RegExp | string[] | RegExp[]
jsxExclude?: string | RegExp | string[] | RegExp[]
}

export async function transformWithOxc(
Expand Down Expand Up @@ -159,9 +161,26 @@ export async function transformWithOxc(

export function oxcPlugin(config: ResolvedConfig): Plugin {
const options = config.oxc as OxcOptions
const { jsxInject, include, exclude, ...oxcTransformOptions } = options
const {
jsxInject,
include,
exclude,
jsxInclude,
jsxExclude,
...oxcTransformOptions
} = options

const filter = createFilter(include || /\.(m?ts|[jt]sx)$/, exclude || /\.js$/)
const defaultInclude = Array.isArray(include)
? include
: [include || /\.(m?ts|[jt]sx)$/]
const filter = createFilter(
defaultInclude.concat(jsxInclude || []),
exclude || /\.js$/,
)
const jsxFilter = createFilter(
jsxInclude || /\.jsx$/,
jsxExclude || /\.(m?[jt]s|tsx)$/,
)

return {
name: 'vite:oxc',
Expand All @@ -178,6 +197,20 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
},
async transform(code, id) {
if (filter(id) || filter(cleanUrl(id))) {
// disable refresh at ssr
if (
this.environment.config.consumer === 'server' &&
oxcTransformOptions.jsx?.refresh
) {
oxcTransformOptions.jsx.refresh = false
}
if (
(jsxFilter(id) || jsxFilter(cleanUrl(id))) &&
!oxcTransformOptions.lang
) {
oxcTransformOptions.lang = 'jsx'
}

const result = await transformWithOxc(
this,
code,
Expand Down

0 comments on commit 3a82b11

Please sign in to comment.