Open floroz opened 1 year ago
I wanted to extend a bit my initial description as I noticed also an issue coming from the sass
compilation, where %placeholders
are expanded into individual style declaration, rather than collapsing class selectors together.
So there seems to be two issues with this pipeline:
sass
compilation of %placeholders
within *.vue
(or *.scss
file consumed via *.vue
) create duplicate style declaration;postcss
plugins are not fully applied until postcss-cli
is run manually on final putputThis is because style in every vue files is transformed individually and so does cssnano. So not possible for merging styles from different files by cssnano. This seems to be a bug for me as we may perform postcss on renderChunk
in build mode.
Thanks for the reply @fi3ework.
This is because style in every vue files is transformed individually and so does cssnano.
Is this by design? If I create .scss
files, shouldn't they be combined before being transformed so that pre-processors can apply their optimizations? (i.e. placeholder collapsing?).
So not possible for merging styles from different files by cssnano. This seems to be a bug for me as we may perform postcss on
renderChunk
in build mode.
Not clear on this point, is this a genuine bug that requires fixing, and therefore the expected behaviour is to have postprocessor optimization run after all stylesheets have been merged together?
Do you know if there is any workaround to apply transformations after styles are combined together?
@floroz Similar to https://github.com/vitejs/vite/issues/7504 https://github.com/vitejs/vite/issues/12400, and the workaround is quite similar to https://github.com/vitejs/vite/issues/12400#issuecomment-1468740126.
7504
Thank you @fi3ework for the resources. Will check and verify those workarounds but it seems they still target the ability to apply postprocessing transformation, which would still invalidate the initial transformation done by sass?
Also, using a enforce: "post"
isn't that different from manually executing postcss
CLI after the vite build
, as presented in my reproduction. (unless there are benefits I am not seeing?).
Could I tap into your knowledge (and slightly outside the boundary of this issue) to ask whether using rollup
directly without vite
could potentially resolve this issue (I suppose at that point the question is with the rollup-vue-plugin
)?
Any update on this? Will this be fixed in v4?
Describe the bug
When running
vite build
with apostcss.config.cjs
file in the project, I would expectpostcss
plugins to run before the finalstyle.css
file is created indist/
.Example:
dist/style.css
postcss dist/styles.css -o dist/styles.css
Reproduction
https://github.com/floroz/vite-css-module-treeshakable
Steps to reproduce
pnpm install
pnpm build
dist/style.css
outputpnpm postcss
(will invokepostcss
CLI on the samedist/style.css
)dist/style.css
output (optimisations are applied)System Info
Used Package Manager
pnpm
Logs
No response
Validations