Home / Function/ oxcPlugin() — vite Function Reference

oxcPlugin() — vite Function Reference

Architecture documentation for the oxcPlugin() function in oxc.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  d06e795b_d030_62c2_8aca_d422635f9891["oxcPlugin()"]
  16dc8750_0d4e_ed3e_3844_b80096ed2e0b["oxc.ts"]
  d06e795b_d030_62c2_8aca_d422635f9891 -->|defined in| 16dc8750_0d4e_ed3e_3844_b80096ed2e0b
  b1b40b5b_3e43_2197_dea0_d36389d312a1["resolvePlugins()"]
  b1b40b5b_3e43_2197_dea0_d36389d312a1 -->|calls| d06e795b_d030_62c2_8aca_d422635f9891
  dfa3f5a8_b519_cb65_4b7e_9d4824406fd4["perEnvironmentPlugin()"]
  d06e795b_d030_62c2_8aca_d422635f9891 -->|calls| dfa3f5a8_b519_cb65_4b7e_9d4824406fd4
  10b9dea8_362c_1af2_93be_afa4dd9aed9e["cleanUrl()"]
  d06e795b_d030_62c2_8aca_d422635f9891 -->|calls| 10b9dea8_362c_1af2_93be_afa4dd9aed9e
  a4adb1a7_cf54_091f_eb63_8217e684a8e1["normalizePath()"]
  d06e795b_d030_62c2_8aca_d422635f9891 -->|calls| a4adb1a7_cf54_091f_eb63_8217e684a8e1
  047aa0d5_25bc_9eb0_8c41_99a2be202642["transformWithOxc()"]
  d06e795b_d030_62c2_8aca_d422635f9891 -->|calls| 047aa0d5_25bc_9eb0_8c41_99a2be202642
  style d06e795b_d030_62c2_8aca_d422635f9891 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/oxc.ts lines 322–471

export function oxcPlugin(config: ResolvedConfig): Plugin {
  if (config.isBundled && config.nativePluginEnabledLevel >= 1) {
    return perEnvironmentPlugin('native:transform', (environment) => {
      const {
        jsxInject,
        include = /\.(m?ts|[jt]sx)$/,
        exclude = /\.js$/,
        jsxRefreshInclude,
        jsxRefreshExclude,
        ..._transformOptions
      } = config.oxc as Exclude<OxcOptions, false | undefined>

      const transformOptions: OxcTransformOptions = _transformOptions
      transformOptions.sourcemap =
        environment.config.mode !== 'build' ||
        !!environment.config.build.sourcemap

      return nativeTransformPlugin({
        root: environment.config.root,
        include,
        exclude,
        jsxRefreshInclude,
        jsxRefreshExclude,
        isServerConsumer: environment.config.consumer === 'server',
        jsxInject,
        transformOptions,
      })
    })
  }

  const options = config.oxc as OxcOptions
  const {
    jsxInject,
    include,
    exclude,
    jsxRefreshInclude,
    jsxRefreshExclude,
    ...oxcTransformOptions
  } = options

  const filter = createFilter(include || /\.(m?ts|[jt]sx)$/, exclude || /\.js$/)
  const jsxRefreshFilter =
    jsxRefreshInclude || jsxRefreshExclude
      ? createFilter(jsxRefreshInclude, jsxRefreshExclude)
      : undefined

  const jsxImportSource =
    (typeof oxcTransformOptions.jsx === 'object' &&
      oxcTransformOptions.jsx.importSource) ||
    'react'
  const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`
  const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`

  const getModifiedOxcTransformOptions = (
    oxcTransformOptions: OxcTransformOptions,
    id: string,
    code: string,
    environment: Environment,
  ): OxcTransformOptions => {
    const result: OxcTransformOptions = {
      ...oxcTransformOptions,
      sourcemap:
        environment.mode !== 'build' || !!environment.config.build.sourcemap,
    }

    const jsxOptions = result.jsx

    // disable refresh based by the same condition as @vitejs/plugin-react
    // https://github.com/vitejs/vite-plugin-react/blob/c8ecad052001b6fc42e508f18433e6b305bca641/packages/plugin-react/src/index.ts#L261-L269
    const [filepath] = id.split('?')
    const isJSX = filepath.endsWith('x')

    if (
      typeof jsxOptions === 'object' &&
      jsxOptions.refresh &&
      (environment.config.consumer === 'server' ||
        (jsxRefreshFilter && !jsxRefreshFilter(id)) ||
        !(
          isJSX ||
          code.includes(jsxImportRuntime) ||
          code.includes(jsxImportDevRuntime)

Domain

Subdomains

Called By

Frequently Asked Questions

What does oxcPlugin() do?
oxcPlugin() is a function in the vite codebase, defined in packages/vite/src/node/plugins/oxc.ts.
Where is oxcPlugin() defined?
oxcPlugin() is defined in packages/vite/src/node/plugins/oxc.ts at line 322.
What does oxcPlugin() call?
oxcPlugin() calls 4 function(s): cleanUrl, normalizePath, perEnvironmentPlugin, transformWithOxc.
What calls oxcPlugin()?
oxcPlugin() is called by 1 function(s): resolvePlugins.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free