Home / File/ esbuildBannerFooterCompatPlugin.ts — vite Source File

esbuildBannerFooterCompatPlugin.ts — vite Source File

Architecture documentation for esbuildBannerFooterCompatPlugin.ts, a typescript file in the vite codebase. 8 imports, 1 dependents.

File typescript PluginSystem LegacySupport 8 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  e9538fc4_20d7_ac58_698b_cf82f4e5db36["esbuildBannerFooterCompatPlugin.ts"]
  5abb8c87_ffcb_f2d4_7421_e36705d9e5c7["plugin.ts"]
  e9538fc4_20d7_ac58_698b_cf82f4e5db36 --> 5abb8c87_ffcb_f2d4_7421_e36705d9e5c7
  1dc2cf7d_5d97_c778_8c33_6449a7607aef["Plugin"]
  e9538fc4_20d7_ac58_698b_cf82f4e5db36 --> 1dc2cf7d_5d97_c778_8c33_6449a7607aef
  7da774f9_eca5_d54e_6e01_6bee7d460a2b["config.ts"]
  e9538fc4_20d7_ac58_698b_cf82f4e5db36 --> 7da774f9_eca5_d54e_6e01_6bee7d460a2b
  eb5604c2_58e1_1c00_5a1a_5d97ea5236ad["ResolvedConfig"]
  e9538fc4_20d7_ac58_698b_cf82f4e5db36 --> eb5604c2_58e1_1c00_5a1a_5d97ea5236ad
  031bc221_67a8_c579_f2bf_bb30a08beeb2["utils.ts"]
  e9538fc4_20d7_ac58_698b_cf82f4e5db36 --> 031bc221_67a8_c579_f2bf_bb30a08beeb2
  abfc9e70_3c15_b3f0_a595_3cf27afb7e64["utils.ts"]
  e9538fc4_20d7_ac58_698b_cf82f4e5db36 --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64
  10b9dea8_362c_1af2_93be_afa4dd9aed9e["cleanUrl"]
  e9538fc4_20d7_ac58_698b_cf82f4e5db36 --> 10b9dea8_362c_1af2_93be_afa4dd9aed9e
  ff79973e_f09f_1c6b_f6b5_d1707df47116["magic-string"]
  e9538fc4_20d7_ac58_698b_cf82f4e5db36 --> ff79973e_f09f_1c6b_f6b5_d1707df47116
  3bf7f0de_2a9f_6f04_cead_0321b3b7af01["index.ts"]
  3bf7f0de_2a9f_6f04_cead_0321b3b7af01 --> e9538fc4_20d7_ac58_698b_cf82f4e5db36
  style e9538fc4_20d7_ac58_698b_cf82f4e5db36 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import MagicString from 'magic-string'
import type { Plugin } from '../plugin'
import type { ResolvedConfig } from '../config'
import { createFilter } from '../utils'
import { cleanUrl } from '../../shared/utils'

/**
 * This plugin supports `esbuild.banner` and `esbuild.footer` options.
 * esbuild supported these options and Vite exposed them.
 * But this should be done by plugin with transform hook.
 * This plugin makes these options work in rolldown-vite as a backward compat for now.
 */
export function esbuildBannerFooterCompatPlugin(
  config: ResolvedConfig,
): Plugin | undefined {
  const options = config.esbuild
  if (!options) return

  const { include, exclude, banner, footer } = options
  if (!banner && !footer) return

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

  return {
    name: 'vite:esbuild-banner-footer-compat',
    transform(code, id) {
      if (filter(id) || filter(cleanUrl(id))) {
        const needsSourcemap =
          this.environment.mode === 'dev' ||
          (this.environment.mode === 'build' &&
            this.environment.config.build.sourcemap)
        if (!needsSourcemap) {
          if (banner) {
            code = `${banner}\n${code}`
          }
          if (footer) {
            code = `${code}\n${footer}`
          }
          return code
        }

        let s: MagicString | undefined
        const str = () => s || (s = new MagicString(code))

        if (banner) {
          str().prepend(`${banner}\n`)
        }
        if (footer) {
          str().append(`${footer}\n`)
        }

        if (s) {
          return {
            code: s.toString(),
            map: s.generateMap({ hires: 'boundary' }),
          }
        }
      }
    },
  }
}

Domain

Subdomains

Frequently Asked Questions

What does esbuildBannerFooterCompatPlugin.ts do?
esbuildBannerFooterCompatPlugin.ts is a source file in the vite codebase, written in typescript. It belongs to the PluginSystem domain, LegacySupport subdomain.
What functions are defined in esbuildBannerFooterCompatPlugin.ts?
esbuildBannerFooterCompatPlugin.ts defines 1 function(s): esbuildBannerFooterCompatPlugin.
What does esbuildBannerFooterCompatPlugin.ts depend on?
esbuildBannerFooterCompatPlugin.ts imports 8 module(s): Plugin, ResolvedConfig, cleanUrl, config.ts, magic-string, plugin.ts, utils.ts, utils.ts.
What files import esbuildBannerFooterCompatPlugin.ts?
esbuildBannerFooterCompatPlugin.ts is imported by 1 file(s): index.ts.
Where is esbuildBannerFooterCompatPlugin.ts in the architecture?
esbuildBannerFooterCompatPlugin.ts is located at packages/vite/src/node/plugins/esbuildBannerFooterCompatPlugin.ts (domain: PluginSystem, subdomain: LegacySupport, directory: packages/vite/src/node/plugins).

Analyze Your Own Codebase

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

Try Supermodel Free