importAnalysisPlugin() — vite Function Reference
Architecture documentation for the importAnalysisPlugin() function in importAnalysis.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD a1fc1de5_905b_efe7_d960_3597604fbdfe["importAnalysisPlugin()"] 5a7b98e4_4eb1_dfca_508b_2d43e2a077e6["importAnalysis.ts"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|defined in| 5a7b98e4_4eb1_dfca_508b_2d43e2a077e6 b1b40b5b_3e43_2197_dea0_d36389d312a1["resolvePlugins()"] b1b40b5b_3e43_2197_dea0_d36389d312a1 -->|calls| a1fc1de5_905b_efe7_d960_3597604fbdfe dfa2b928_25a4_a78f_1e11_1e7e643cae09["resolve()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| dfa2b928_25a4_a78f_1e11_1e7e643cae09 ae0e5a50_b89b_8a12_820a_fee4d319a219["getAliasPatternMatcher()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| ae0e5a50_b89b_8a12_820a_fee4d319a219 28e3e193_a739_1920_1735_eeb2a70f2fde["serializeDefine()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| 28e3e193_a739_1920_1735_eeb2a70f2fde 43ca84ae_e45b_14be_42cf_f0f6bbfc3634["canSkipImportAnalysis()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| 43ca84ae_e45b_14be_42cf_f0f6bbfc3634 0850ad90_f980_60a3_ab1f_b17433109b74["prettifyUrl()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| 0850ad90_f980_60a3_ab1f_b17433109b74 cd901a4b_1290_4e3f_0c59_f8621634cb5a["stripBomTag()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| cd901a4b_1290_4e3f_0c59_f8621634cb5a 1976bcb9_a492_4760_b3a8_ad9296c5c6ba["createParseErrorInfo()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| 1976bcb9_a492_4760_b3a8_ad9296c5c6ba c21bd4cb_400a_15f5_15eb_1de2be5b3418["throwOutdatedRequest()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| c21bd4cb_400a_15f5_15eb_1de2be5b3418 2f681ea7_f0dd_ef5c_cb52_1396d02e37d7["handlePrunedModules()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| 2f681ea7_f0dd_ef5c_cb52_1396d02e37d7 14c1c6b3_e4b1_62ce_7196_077ecd00ef57["timeFrom()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| 14c1c6b3_e4b1_62ce_7196_077ecd00ef57 26e0aa25_abdb_a755_dedb_61e78323162d["moduleListContains()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| 26e0aa25_abdb_a755_dedb_61e78323162d a4adb1a7_cf54_091f_eb63_8217e684a8e1["normalizePath()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| a4adb1a7_cf54_091f_eb63_8217e684a8e1 style a1fc1de5_905b_efe7_d960_3597604fbdfe fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/importAnalysis.ts lines 224–872
export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
const { root, base } = config
const clientPublicPath = path.posix.join(base, CLIENT_PUBLIC_PATH)
const enablePartialAccept = config.experimental.hmrPartialAccept
const matchAlias = getAliasPatternMatcher(config.resolve.alias)
let _env: string | undefined
let _ssrEnv: string | undefined
function getEnv(ssr: boolean) {
if (!_ssrEnv || !_env) {
const importMetaEnvKeys: Record<string, any> = {}
const userDefineEnv: Record<string, any> = {}
for (const key in config.env) {
importMetaEnvKeys[key] = JSON.stringify(config.env[key])
}
for (const key in config.define) {
// non-import.meta.env.* is handled in `clientInjection` plugin
if (key.startsWith('import.meta.env.')) {
userDefineEnv[key.slice(16)] = config.define[key]
}
}
const env = `import.meta.env = ${serializeDefine({
...importMetaEnvKeys,
SSR: '__vite_ssr__',
...userDefineEnv,
})};`
_ssrEnv = env.replace('__vite_ssr__', 'true')
_env = env.replace('__vite_ssr__', 'false')
}
return ssr ? _ssrEnv : _env
}
return {
name: 'vite:import-analysis',
async transform(source, importer) {
const environment = this.environment as DevEnvironment
const ssr = environment.config.consumer === 'server'
const moduleGraph = environment.moduleGraph
if (canSkipImportAnalysis(importer)) {
debug?.(colors.dim(`[skipped] ${prettifyUrl(importer, root)}`))
return null
}
const msAtStart = debug ? performance.now() : 0
await init
let imports!: readonly ImportSpecifier[]
let exports!: readonly ExportSpecifier[]
source = stripBomTag(source)
try {
;[imports, exports] = parseImports(source)
} catch (_e: unknown) {
const e = _e as EsModuleLexerParseError
const { message, showCodeFrame } = createParseErrorInfo(
importer,
source,
)
this.error(message, showCodeFrame ? e.idx : undefined)
}
const depsOptimizer = environment.depsOptimizer
// since we are already in the transform phase of the importer, it must
// have been loaded so its entry is guaranteed in the module graph.
const importerModule = moduleGraph.getModuleById(importer)
if (!importerModule) {
// This request is no longer valid. It could happen for optimized deps
// requests. A full reload is going to request this id again.
// Throwing an outdated error so we properly finish the request with a
// 504 sent to the browser.
throwOutdatedRequest(importer)
}
if (
!imports.length &&
!(this as unknown as TransformPluginContext)._addedImports
) {
const prunedImports = await moduleGraph.updateModuleInfo(
importerModule,
new Set(),
Domain
Subdomains
Calls
- canSkipImportAnalysis()
- checkPublicFile()
- cleanUrl()
- createParseErrorInfo()
- error()
- extractImportedBindings()
- fsPathFromUrl()
- generateCodeFrame()
- getAliasPatternMatcher()
- handlePrunedModules()
- injectQuery()
- interopNamedImports()
- isBuiltin()
- isCSSRequest()
- isDataUrl()
- isExplicitImportRequired()
- isExternalUrl()
- isFilePathESM()
- isInNodeModules()
- joinUrlSegments()
- lexAcceptedHmrDeps()
- lexAcceptedHmrExports()
- mergeAcceptedUrls()
- moduleListContains()
- normalizeHmrUrl()
- normalizePath()
- normalizeResolvedIdToUrl()
- optimizedDepInfoFromFile()
- optimizedDepNeedsInterop()
- prettifyUrl()
- removeImportQuery()
- removeTimestampQuery()
- resolve()
- serializeDefine()
- shouldExternalize()
- stripBase()
- stripBomTag()
- throwOutdatedRequest()
- timeFrom()
- transform()
- transformStableResult()
- unwrapId()
- warmupRequest()
- warn()
- withTrailingSlash()
- wrapId()
Called By
Source
Frequently Asked Questions
What does importAnalysisPlugin() do?
importAnalysisPlugin() is a function in the vite codebase, defined in packages/vite/src/node/plugins/importAnalysis.ts.
Where is importAnalysisPlugin() defined?
importAnalysisPlugin() is defined in packages/vite/src/node/plugins/importAnalysis.ts at line 224.
What does importAnalysisPlugin() call?
importAnalysisPlugin() calls 46 function(s): canSkipImportAnalysis, checkPublicFile, cleanUrl, createParseErrorInfo, error, extractImportedBindings, fsPathFromUrl, generateCodeFrame, and 38 more.
What calls importAnalysisPlugin()?
importAnalysisPlugin() 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