buildImportAnalysisPlugin() — vite Function Reference
Architecture documentation for the buildImportAnalysisPlugin() function in importAnalysisBuild.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 6d315957_5b5c_845c_10c4_b8cb46bc58eb["buildImportAnalysisPlugin()"] 04ad4685_2ce3_556a_152b_c93668a74b3b["importAnalysisBuild.ts"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|defined in| 04ad4685_2ce3_556a_152b_c93668a74b3b 8c4db194_5dfd_4391_cc9a_833655009196["resolveBuildPlugins()"] 8c4db194_5dfd_4391_cc9a_833655009196 -->|calls| 6d315957_5b5c_845c_10c4_b8cb46bc58eb 51afdf58_3045_64b1_cf5b_929b1091e877["get()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| 51afdf58_3045_64b1_cf5b_929b1091e877 7e08b9a5_2650_5312_63d2_5971015349af["numberToPos()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| 7e08b9a5_2650_5312_63d2_5971015349af 310ed049_c1b4_c917_b399_81bab290e5a2["generateCodeFrame()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| 310ed049_c1b4_c917_b399_81bab290e5a2 1026d697_d151_fe44_5983_b0479369261c["findPreloadMarker()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| 1026d697_d151_fe44_5983_b0479369261c 0b9e0d55_d22c_da82_ca1d_a2e7d0af1d66["toOutputFilePathInJS()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| 0b9e0d55_d22c_da82_ca1d_a2e7d0af1d66 6d8b0c42_77dd_1f09_c23b_25bba559c5df["toRelativePath()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| 6d8b0c42_77dd_1f09_c23b_25bba559c5df cb1210e8_03e9_2eec_ef04_aa15d44d4c08["combineSourcemaps()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| cb1210e8_03e9_2eec_ef04_aa15d44d4c08 0857a370_8db0_3f2b_ac58_b48c57bd6a12["genSourceMapUrl()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| 0857a370_8db0_3f2b_ac58_b48c57bd6a12 dfa3f5a8_b519_cb65_4b7e_9d4824406fd4["perEnvironmentPlugin()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| dfa3f5a8_b519_cb65_4b7e_9d4824406fd4 36e0844c_58c5_5f68_8102_cdd7d207e92c["getPreloadCode()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| 36e0844c_58c5_5f68_8102_cdd7d207e92c style 6d315957_5b5c_845c_10c4_b8cb46bc58eb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/importAnalysisBuild.ts lines 200–577
export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin[] {
const getInsertPreload = (environment: PartialEnvironment) =>
environment.config.consumer === 'client' &&
!config.isWorker &&
!config.build.lib
const renderBuiltUrl = config.experimental.renderBuiltUrl
const isRelativeBase = config.base === './' || config.base === ''
const plugin: Plugin = {
name: 'vite:build-import-analysis',
renderChunk(code, _, { format }) {
// make sure we only perform the preload logic in modern builds.
if (code.indexOf(isModernFlag) > -1) {
const re = new RegExp(isModernFlag, 'g')
const isModern = String(format === 'es')
const isModernWithPadding =
isModern + ' '.repeat(isModernFlag.length - isModern.length)
return {
code: code.replace(re, isModernWithPadding),
map: null,
}
}
return null
},
async generateBundle({ format }, bundle) {
if (format !== 'es') {
return
}
await init
// If preload is not enabled, we parse through each imports and remove any imports to pure CSS chunks
// as they are removed from the bundle
if (!getInsertPreload(this.environment)) {
const removedPureCssFiles = removedPureCssFilesCache.get(config)
if (removedPureCssFiles && removedPureCssFiles.size > 0) {
for (const file in bundle) {
const chunk = bundle[file]
if (chunk.type === 'chunk' && chunk.code.includes('import')) {
const code = chunk.code
let imports!: ImportSpecifier[]
try {
imports = parseImports(code)[0].filter((i) => i.d > -1)
} catch (e: any) {
const loc = numberToPos(code, e.idx)
this.error({
name: e.name,
message: e.message,
stack: e.stack,
cause: e.cause,
pos: e.idx,
loc: { ...loc, file: chunk.fileName },
frame: generateCodeFrame(code, loc),
})
}
for (const imp of imports) {
const {
n: name,
s: start,
e: end,
ss: expStart,
se: expEnd,
} = imp
let url = name
if (!url) {
const rawUrl = code.slice(start, end)
if (
(rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`) ||
(rawUrl[0] === '`' && rawUrl[rawUrl.length - 1] === '`')
)
url = rawUrl.slice(1, -1)
}
if (!url) continue
const normalizedFile = path.posix.join(
path.posix.dirname(chunk.fileName),
url,
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does buildImportAnalysisPlugin() do?
buildImportAnalysisPlugin() is a function in the vite codebase, defined in packages/vite/src/node/plugins/importAnalysisBuild.ts.
Where is buildImportAnalysisPlugin() defined?
buildImportAnalysisPlugin() is defined in packages/vite/src/node/plugins/importAnalysisBuild.ts at line 200.
What does buildImportAnalysisPlugin() call?
buildImportAnalysisPlugin() calls 10 function(s): combineSourcemaps, findPreloadMarker, genSourceMapUrl, generateCodeFrame, get, getPreloadCode, numberToPos, perEnvironmentPlugin, and 2 more.
What calls buildImportAnalysisPlugin()?
buildImportAnalysisPlugin() is called by 1 function(s): resolveBuildPlugins.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free