MCPcopy
hub / github.com/vitejs/vite / finalizeCss

Function finalizeCss

packages/vite/src/node/plugins/css.ts:1918–1937  ·  view source on GitHub ↗
(css: string, config: ResolvedConfig)

Source from the content-addressed store, hash-verified

1916const viteHashUpdateMarkerRE = /\/\*\$vite\$:\d+\*\//
1917
1918async function finalizeCss(css: string, config: ResolvedConfig) {
1919 // hoist external @imports and @charset to the top of the CSS chunk per spec (#1845 and #6333)
1920 if (css.includes('@import') || css.includes('@charset')) {
1921 css = hoistAtRules(css)
1922 }
1923 if (config.build.cssMinify) {
1924 css = await minifyCSS(css, config, false)
1925 }
1926 // inject an additional string to generate a different hash for https://github.com/vitejs/vite/issues/18038
1927 //
1928 // pre-5.4.3, we generated CSS link tags without crossorigin attribute and generated an hash without
1929 // this string
1930 // in 5.4.3, we added crossorigin attribute to the generated CSS link tags but that made chromium browsers
1931 // to block the CSSs from loading due to chromium's weird behavior
1932 // (https://www.hacksoft.io/blog/handle-images-cors-error-in-chrome, https://issues.chromium.org/issues/40381978)
1933 // to avoid that happening, we inject an additional string so that a different hash is generated
1934 // for the same CSS content
1935 css += viteHashUpdateMarker
1936 return css
1937}
1938
1939interface PostCSSConfigResult {
1940 options: PostCSS.ProcessOptions

Callers 2

renderChunkFunction · 0.85
generateBundleFunction · 0.85

Calls 2

hoistAtRulesFunction · 0.85
minifyCSSFunction · 0.85

Tested by

no test coverage detected