Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(css): only run postcss when needed #19061

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sapphi-red
Copy link
Member

Description

@sapphi-red sapphi-red added feat: css p2-nice-to-have Not breaking anything but nice to have (priority) labels Dec 24, 2024
Comment on lines +1310 to 1319
// postcss processing is not needed
if (
lang === 'css' &&
lang !== 'sss' &&
!postcssConfig &&
!isModule &&
!needInlineImport &&
!hasUrl
) {
return { code, map: null }
return { code, map: preprocessorMap ?? null, deps }
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR, If the preprocessor removed all @import, we might be able to return at this line. (previously postcss was run)

Comment on lines +1386 to 1395
if (
urlReplacer &&
// if there's an @import, we need to add this plugin
// regradless of whether it contains url() or image-set(),
// because we don't know the content referenced by @import
(needInlineImport || cssUrlRE.test(code) || cssImageSetRE.test(code))
) {
postcssPlugins.push(
UrlRewritePostcssPlugin({
replacer: urlReplacer,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UrlRewritePostcssPlugin was always pushed, so postcss was ran always.

@@ -1428,7 +1433,7 @@ async function compileCSS(
)
}

if (!postcssPlugins.length) {
if (lang !== 'sss' && !postcssPlugins.length) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lang !== 'sss' was not needed because !postcssPlugins.length was always false.

@@ -1509,7 +1516,6 @@ async function compileCSS(

if (!devSourcemap) {
return {
ast: postcssResult,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ast was not used anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sourcemaps changed because postcss does not run on these files anymore.

@sapphi-red
Copy link
Member Author

/ecosystem-ci run

Copy link

pkg-pr-new bot commented Dec 25, 2024

Open in Stackblitz

npm i https://pkg.pr.new/vite@19061

commit: 4c777ac

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 4c777ac: Open

suite result latest scheduled
histoire failure failure
ladle failure success
redwoodjs failure failure
remix failure failure
vite-plugin-svelte failure failure
vitest failure success
waku failure failure

analogjs, astro, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, storybook, sveltekit, unocss, vike, vite-environment-examples, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress

@sapphi-red
Copy link
Member Author

ladle fail is not related to this PR. vitest is failing because of the change in #19004. So it should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p2-nice-to-have Not breaking anything but nice to have (priority) trigger: preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant