getEmptyChunkReplacer() — vite Function Reference
Architecture documentation for the getEmptyChunkReplacer() function in css.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 98ef77ec_2e97_a945_fa45_32171e0ad8dc["getEmptyChunkReplacer()"] c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"] 98ef77ec_2e97_a945_fa45_32171e0ad8dc -->|defined in| c3eb47df_971b_0616_6c9f_29b3ded72224 cd131d16_e223_ab79_1b7c_8ea449ae51a2["cssPostPlugin()"] cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 98ef77ec_2e97_a945_fa45_32171e0ad8dc 5e378bd7_4558_94a6_54bf_d9742f54d2e9["escapeRegex()"] 98ef77ec_2e97_a945_fa45_32171e0ad8dc -->|calls| 5e378bd7_4558_94a6_54bf_d9742f54d2e9 style 98ef77ec_2e97_a945_fa45_32171e0ad8dc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/css.ts lines 1238–1272
export function getEmptyChunkReplacer(
pureCssChunkNames: string[],
outputFormat: InternalModuleFormat,
): (code: string) => string {
const emptyChunkFiles = pureCssChunkNames
.map((file) => escapeRegex(path.basename(file)))
.join('|')
// for cjs, require calls might be chained by minifier using the comma operator.
// in this case we have to keep one comma if a next require is chained
// or add a semicolon to terminate the chain.
const emptyChunkRE = new RegExp(
outputFormat === 'es'
? `\\bimport\\s*["'][^"']*(?:${emptyChunkFiles})["'];`
: `(\\b|,\\s*)require\\(\\s*["'\`][^"'\`]*(?:${emptyChunkFiles})["'\`]\\)(;|,)`,
'g',
)
return (code: string) =>
code.replace(
emptyChunkRE,
// remove css import while preserving source map location
(m, p1, p2) => {
if (outputFormat === 'es') {
return `/* empty css ${''.padEnd(m.length - 15)}*/`
}
if (p2 === ';') {
// if it ends with `;`, move it before and remove the leading `,`
return `${p2}/* empty css ${''.padEnd(m.length - 16)}*/`
}
// if it ends with `,`, remove it but keep the leading `,` if exists
return `${p1}/* empty css ${''.padEnd(m.length - 15 - p1.length)}*/`
},
)
}
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does getEmptyChunkReplacer() do?
getEmptyChunkReplacer() is a function in the vite codebase, defined in packages/vite/src/node/plugins/css.ts.
Where is getEmptyChunkReplacer() defined?
getEmptyChunkReplacer() is defined in packages/vite/src/node/plugins/css.ts at line 1238.
What does getEmptyChunkReplacer() call?
getEmptyChunkReplacer() calls 1 function(s): escapeRegex.
What calls getEmptyChunkReplacer()?
getEmptyChunkReplacer() is called by 1 function(s): cssPostPlugin.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free