PluginContainer Class — vite Architecture
Architecture documentation for the PluginContainer class in pluginContainer.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD e095f407_f809_eb3e_608e_d152e6847d0a["PluginContainer"] 3b8df068_35d0_2c94_3ad1_e93c93d1d613["pluginContainer.ts"] e095f407_f809_eb3e_608e_d152e6847d0a -->|defined in| 3b8df068_35d0_2c94_3ad1_e93c93d1d613 f62d2d4b_456b_a0b4_866e_de5641a84714["constructor()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| f62d2d4b_456b_a0b4_866e_de5641a84714 4157452b_1286_c3e8_9e8a_c702bce01b69["_getEnvironment()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| 4157452b_1286_c3e8_9e8a_c702bce01b69 bdc17ca5_0ac7_3179_22ec_ade8f3ccd777["_getPluginContainer()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| bdc17ca5_0ac7_3179_22ec_ade8f3ccd777 87053f75_eb97_15a1_9d01_3e7bf0db1f33["getModuleInfo()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| 87053f75_eb97_15a1_9d01_3e7bf0db1f33 57e7f823_7340_c130_293b_c7cff61b3d12["options()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| 57e7f823_7340_c130_293b_c7cff61b3d12 7d1c05d4_ce0d_0c56_2bf5_2f0334fa2587["buildStart()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| 7d1c05d4_ce0d_0c56_2bf5_2f0334fa2587 628949fc_291a_1d05_3fc0_9f461f634c18["watchChange()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| 628949fc_291a_1d05_3fc0_9f461f634c18 acb05845_9984_6792_9aae_b58486b613b5["resolveId()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| acb05845_9984_6792_9aae_b58486b613b5 979a55e8_d076_d451_f023_e6c68b6790de["load()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| 979a55e8_d076_d451_f023_e6c68b6790de e1266b03_e0f1_635b_5994_e16420bc0263["transform()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| e1266b03_e0f1_635b_5994_e16420bc0263 969cb910_e45f_4b10_e707_9ec8d9fcc8d8["close()"] e095f407_f809_eb3e_608e_d152e6847d0a -->|method| 969cb910_e45f_4b10_e707_9ec8d9fcc8d8
Relationship Graph
Source Code
packages/vite/src/node/server/pluginContainer.ts lines 1182–1309
class PluginContainer {
constructor(private environments: Record<string, Environment>) {}
// Backward compatibility
// Users should call pluginContainer.resolveId (and load/transform) passing the environment they want to work with
// But there is code that is going to call it without passing an environment, or with the ssr flag to get the ssr environment
private _getEnvironment(options?: {
ssr?: boolean
environment?: Environment
}) {
return options?.environment
? options.environment
: this.environments[options?.ssr ? 'ssr' : 'client']
}
private _getPluginContainer(options?: {
ssr?: boolean
environment?: Environment
}) {
return (this._getEnvironment(options) as DevEnvironment).pluginContainer
}
getModuleInfo(id: string): ModuleInfo | null {
const clientModuleInfo = (
this.environments.client as DevEnvironment
).pluginContainer.getModuleInfo(id)
const ssrModuleInfo = (
this.environments.ssr as DevEnvironment
).pluginContainer.getModuleInfo(id)
if (clientModuleInfo == null && ssrModuleInfo == null) return null
return new Proxy({} as any, {
get: (_, key: string) => {
// `meta` refers to `ModuleInfo.meta` of both environments, so we also
// need to merge it here
if (key === 'meta') {
const meta: Record<string, any> = {}
if (ssrModuleInfo) {
Object.assign(meta, ssrModuleInfo.meta)
}
if (clientModuleInfo) {
Object.assign(meta, clientModuleInfo.meta)
}
return meta
}
if (clientModuleInfo) {
if (key in clientModuleInfo) {
return clientModuleInfo[key as keyof ModuleInfo]
}
}
if (ssrModuleInfo) {
if (key in ssrModuleInfo) {
return ssrModuleInfo[key as keyof ModuleInfo]
}
}
},
})
}
get options(): InputOptions {
return (this.environments.client as DevEnvironment).pluginContainer.options
}
// For backward compatibility, buildStart and watchChange are called only for the client environment
// buildStart is called per environment for a plugin with the perEnvironmentStartEndDuringDev flag
// watchChange is called per environment for a plugin with the perEnvironmentWatchChangeDuringDev flag
async buildStart(_options?: InputOptions): Promise<void> {
return (
this.environments.client as DevEnvironment
).pluginContainer.buildStart(_options)
}
async watchChange(
id: string,
change: { event: 'create' | 'update' | 'delete' },
): Promise<void> {
return (
this.environments.client as DevEnvironment
).pluginContainer.watchChange(id, change)
Domain
Source
Frequently Asked Questions
What is the PluginContainer class?
PluginContainer is a class in the vite codebase, defined in packages/vite/src/node/server/pluginContainer.ts.
Where is PluginContainer defined?
PluginContainer is defined in packages/vite/src/node/server/pluginContainer.ts at line 1182.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free