Skip to content

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.

}

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.

Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit confused about this part. Isn't sugarss support added as a postcss plugin, so postcssPlugins.length should be at least one?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because sugarss is a parser and not a plugin.

parser: lang === 'sss' ? loadSss(config.root) : postcssOptions.parser,

Now that you mentioned about it, I think we should change this condition to lang !== 'sss' && !postcssOptions.parser && !postcssPlugins.length.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I didn't know it's a parser. Yeah I think checking for parser seems better too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated 👍


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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 25, 2024

Open in Stackblitz

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

commit: d00ce43

@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.

bluwy
bluwy previously approved these changes Jan 7, 2025
patak-dev
patak-dev previously approved these changes Jan 7, 2025
@sapphi-red sapphi-red dismissed stale reviews from patak-dev and bluwy via d00ce43 January 24, 2025 03:07
@sapphi-red sapphi-red added this to the 6.1 milestone Jan 24, 2025
@sapphi-red sapphi-red merged commit 30194fa into vitejs:main Jan 24, 2025
16 checks passed
@sapphi-red sapphi-red deleted the perf/css-only-run-postcss-when-needed branch January 24, 2025 03:32
moonlitusun pushed a commit to moonlitusun/vite that referenced this pull request May 25, 2025
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.

3 participants