PluginContext Class — vite Architecture
Architecture documentation for the PluginContext class in pluginContainer.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD c261dae5_9c68_4b7d_8b09_fe13190425fe["PluginContext"] 3b8df068_35d0_2c94_3ad1_e93c93d1d613["pluginContainer.ts"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|defined in| 3b8df068_35d0_2c94_3ad1_e93c93d1d613 fd9b7486_6d15_de09_fa86_a81fd2f92598["pluginName()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| fd9b7486_6d15_de09_fa86_a81fd2f92598 93cb8fbb_3278_873c_e53e_2420ec32377e["constructor()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| 93cb8fbb_3278_873c_e53e_2420ec32377e 2ed2578e_588a_efd0_df6b_829e1a96adf2["parse()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| 2ed2578e_588a_efd0_df6b_829e1a96adf2 dfa2b928_25a4_a78f_1e11_1e7e643cae09["resolve()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| dfa2b928_25a4_a78f_1e11_1e7e643cae09 94464637_e13d_00af_69ed_f92d6e6cc584["load()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| 94464637_e13d_00af_69ed_f92d6e6cc584 4b121a62_0595_c8a4_a564_94500f5fbaf5["getModuleInfo()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| 4b121a62_0595_c8a4_a564_94500f5fbaf5 d1db0d45_eb52_3b21_c1e3_ccd6295c19cb["_updateModuleInfo()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| d1db0d45_eb52_3b21_c1e3_ccd6295c19cb 6e26599c_f00d_453c_382a_534a302dec9f["getModuleIds()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| 6e26599c_f00d_453c_382a_534a302dec9f 31d5b2c5_2267_3dde_fc85_e309cf15eb0d["addWatchFile()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| 31d5b2c5_2267_3dde_fc85_e309cf15eb0d d77caba7_9090_1989_ff22_f5ffe55b1a5e["getWatchFiles()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| d77caba7_9090_1989_ff22_f5ffe55b1a5e 2413bb83_2f00_e69b_72f7_3b56a2779134["emitFile()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| 2413bb83_2f00_e69b_72f7_3b56a2779134 5a26a304_a297_15bc_8fd2_0e49e787d80f["setAssetSource()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| 5a26a304_a297_15bc_8fd2_0e49e787d80f 1adea094_39cf_72a2_c028_30a7e4665b35["getFileName()"] c261dae5_9c68_4b7d_8b09_fe13190425fe -->|method| 1adea094_39cf_72a2_c028_30a7e4665b35
Relationship Graph
Source Code
packages/vite/src/node/server/pluginContainer.ts lines 744–1031
class PluginContext
extends MinimalPluginContext
implements Omit<RollupPluginContext, 'cache'>
{
ssr = false
_scan = false
_activeId: string | null = null
_activeCode: string | null = null
_resolveSkips?: Set<Plugin>
_resolveSkipCalls?: readonly SkipInformation[]
override get pluginName(): string {
return this._plugin.name
}
constructor(
public _plugin: Plugin,
public _container: EnvironmentPluginContainer,
) {
super(_container.minimalContext.meta, _container.environment)
}
fs: RollupFsModule = fsModule
parse(code: string, opts: any): Program {
return rolldownParseAst(code, opts)
}
async resolve(
id: string,
importer?: string,
options?: {
attributes?: Record<string, string>
custom?: CustomPluginOptions
isEntry?: boolean
skipSelf?: boolean
},
): Promise<ResolvedId | null> {
let skipCalls: readonly SkipInformation[] | undefined
if (options?.skipSelf === false) {
skipCalls = this._resolveSkipCalls
} else if (this._resolveSkipCalls) {
const skipCallsTemp = [...this._resolveSkipCalls]
const sameCallIndex = this._resolveSkipCalls.findIndex(
(c) =>
c.id === id && c.importer === importer && c.plugin === this._plugin,
)
if (sameCallIndex !== -1) {
skipCallsTemp[sameCallIndex] = {
...skipCallsTemp[sameCallIndex],
called: true,
}
} else {
skipCallsTemp.push({ id, importer, plugin: this._plugin })
}
skipCalls = skipCallsTemp
} else {
skipCalls = [{ id, importer, plugin: this._plugin }]
}
let out = await this._container.resolveId(id, importer, {
attributes: options?.attributes,
custom: options?.custom,
isEntry: !!options?.isEntry,
skip: this._resolveSkips,
skipCalls,
scan: this._scan,
})
if (typeof out === 'string') out = { id: out }
return out as ResolvedId | null
}
async load(
options: {
id: string
resolveDependencies?: boolean
} & Partial<PartialNull<ModuleOptions>>,
): Promise<ModuleInfo> {
// We may not have added this to our module graph yet, so ensure it exists
await this._container.moduleGraph?.ensureEntryFromUrl(unwrapId(options.id))
// Not all options passed to this function make sense in the context of loading individual files,
Domain
Source
Frequently Asked Questions
What is the PluginContext class?
PluginContext is a class in the vite codebase, defined in packages/vite/src/node/server/pluginContainer.ts.
Where is PluginContext defined?
PluginContext is defined in packages/vite/src/node/server/pluginContainer.ts at line 744.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free