compilePostCSS() — vite Function Reference
Architecture documentation for the compilePostCSS() function in css.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 6aa50cd4_4412_2a02_b76b_495614715811["compilePostCSS()"] c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|defined in| c3eb47df_971b_0616_6c9f_29b3ded72224 c641d137_b4cd_833f_0387_7d29ec90fde1["compileCSS()"] c641d137_b4cd_833f_0387_7d29ec90fde1 -->|calls| 6aa50cd4_4412_2a02_b76b_495614715811 cef0333b_923a_6cea_cbaf_2d72f8dd2e53["resolvePostcssConfig()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| cef0333b_923a_6cea_cbaf_2d72f8dd2e53 b1f5b07b_f692_69cd_1795_627055928bb7["getTopLevelConfig()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| b1f5b07b_f692_69cd_1795_627055928bb7 40ac1f90_7a40_f7a5_f25c_701a010aa803["getAtImportResolvers()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| 40ac1f90_7a40_f7a5_f25c_701a010aa803 ba7684aa_ebba_10ec_acf9_5ab88c7bba74["importPostcssImport()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| ba7684aa_ebba_10ec_acf9_5ab88c7bba74 dfa2b928_25a4_a78f_1e11_1e7e643cae09["resolve()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| dfa2b928_25a4_a78f_1e11_1e7e643cae09 be351481_35b7_f392_a229_ac14e1fa7efb["checkPublicFile()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb 3eaf8b50_562d_6dc6_0d63_a33906ef9339["isPreProcessor()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| 3eaf8b50_562d_6dc6_0d63_a33906ef9339 e0336cc5_add2_5b51_6027_5f5c568b2852["compileCSSPreprocessors()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| e0336cc5_add2_5b51_6027_5f5c568b2852 9d025481_71dc_8fbb_c07e_b6e74a08a45a["getHash()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| 9d025481_71dc_8fbb_c07e_b6e74a08a45a f9a13b61_758d_6973_4d25_637ddaa2a22f["url()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| f9a13b61_758d_6973_4d25_637ddaa2a22f 755548d7_400f_08c3_553a_1301bf36475f["plugins()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| 755548d7_400f_08c3_553a_1301bf36475f bf50047e_a0e3_48b6_aa97_2e41d9b50e56["UrlRewritePostcssPlugin()"] 6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| bf50047e_a0e3_48b6_aa97_2e41d9b50e56 style 6aa50cd4_4412_2a02_b76b_495614715811 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/css.ts lines 1491–1664
async function compilePostCSS(
environment: PartialEnvironment,
id: string,
code: string,
deps: Set<string>,
lang: CssLang | undefined,
workerController: PreprocessorWorkerController,
urlResolver?: CssUrlResolver,
): Promise<
| {
code: string
map?: Exclude<SourceMapInput, string>
modules?: Record<string, string>
}
| undefined
> {
const { config } = environment
const { modules: modulesOptions, devSourcemap } = config.css
const isModule = modulesOptions !== false && cssModuleRE.test(id)
// although at serve time it can work without processing, we do need to
// crawl them in order to register watch dependencies.
const needInlineImport = code.includes('@import')
const hasUrl = cssUrlRE.test(code) || cssImageSetRE.test(code)
const postcssConfig = await resolvePostcssConfig(
environment.getTopLevelConfig(),
)
// postcss processing is not needed
if (
lang !== 'sss' &&
!postcssConfig &&
!isModule &&
!needInlineImport &&
!hasUrl
) {
return
}
// postcss
const atImportResolvers = getAtImportResolvers(
environment.getTopLevelConfig(),
)
const postcssPlugins = postcssConfig?.plugins.slice() ?? []
if (needInlineImport) {
postcssPlugins.unshift(
(await importPostcssImport()).default({
async resolve(id, basedir) {
const publicFile = checkPublicFile(
id,
environment.getTopLevelConfig(),
)
if (publicFile) {
return publicFile
}
const resolved = await atImportResolvers.css(
environment,
id,
path.join(basedir, '*'),
)
if (resolved) {
return path.resolve(resolved)
}
// postcss-import falls back to `resolve` dep if this is unresolved,
// but we've shimmed to remove the `resolve` dep to cut on bundle size.
// warn here to provide a better error message.
if (!path.isAbsolute(id)) {
environment.logger.error(
colors.red(
`Unable to resolve \`@import "${id}"\` from ${basedir}`,
),
)
}
return id
},
async load(id) {
const code = await fs.promises.readFile(id, 'utf-8')
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does compilePostCSS() do?
compilePostCSS() is a function in the vite codebase, defined in packages/vite/src/node/plugins/css.ts.
Where is compilePostCSS() defined?
compilePostCSS() is defined in packages/vite/src/node/plugins/css.ts at line 1491.
What does compilePostCSS() call?
compilePostCSS() calls 18 function(s): UrlRewritePostcssPlugin, checkPublicFile, compileCSSPreprocessors, error, getAtImportResolvers, getCssResolversKeys, getHash, getTopLevelConfig, and 10 more.
What calls compilePostCSS()?
compilePostCSS() is called by 1 function(s): compileCSS.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free