(css: string, config: ResolvedConfig)
| 1916 | const viteHashUpdateMarkerRE = /\/\*\$vite\$:\d+\*\// |
| 1917 | |
| 1918 | async 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 | |
| 1939 | interface PostCSSConfigResult { |
| 1940 | options: PostCSS.ProcessOptions |
no test coverage detected