Postcss plugins not applied #8693
-
I am trying to optimize the generated CSS files from my Vue3 + Typescript + Vite project. The project is based on https://github.com/wuruoyun/vue-component-lib-starter and I am trying to get This is my const path = require("path");
const { defineConfig } = require("vite");
import vue from "@vitejs/plugin-vue";
const packageName = "complib-faasaf-io";
module.exports = defineConfig({
plugins: [vue()], // to process SFC
css: {
postcss: {
plugins: [
require("postcss-combine-media-query"),
require("postcss-combine-duplicated-selectors"),
require("postcss-prettify"),
],
},
},
build: {
lib: {
entry: path.resolve(__dirname, "src/index.ts"),
name: packageName,
formats: ["es"], // adding 'umd' requires globals set to every external module
fileName: (format) => `${packageName}.${format}.js`,
},
rollupOptions: {
// external modules won't be bundled into your library
external: ["vue"], // not every external has a global
output: {
// disable warning on src/index.ts using both default and named export
exports: "named",
// Provide global variables to use in the UMD build
// for externalized deps (not useful if 'umd' is not in lib.formats)
globals: {
vue: "Vue",
},
},
},
emptyOutDir: false, // to retain the types folder generated by tsc
},
}); Can anyone spot what I am doing wrong? [UDPATE]: It seems that the plugins are applied, however I have to run postcss another time after the build process. Does postcss only run after each scss file has been parsed? I am confused to how this is implemented in vite. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
I've also just diagnosed this issue with vite and postcss-preset-env. Has there been any fix or work around for this? |
Beta Was this translation helpful? Give feedback.
-
I had a similar issue, the problem I was facing is that when I added vite and tailwind support (moving away from webpack) my existing project was still using cjs but the configuration I had for vite and tailwind was using esm, so I had fully converted my project to esm standards |
Beta Was this translation helpful? Give feedback.
-
I had the opposite issue: vite would not recognize a standalone I think it has to do with ESM modules. Vite only recognizes So a // postcss.config.js
// ESM module. does not work.
import purgecss from '@fullhuman/postcss-purgecss';
export const plugins = [
purgecss({
content: [
'./index.html',
'./src/**/*.{vue,js,ts}'
],
variables: true,
safelist: {
// Keep leaflet classes
standard: [/leaflet-/]
}
})
]; what does work is including the postcss config inside of // vite.config.ts
import {fileURLToPath, URL} from 'node:url';
import {defineConfig} from 'vite';
import purgecss from '@fullhuman/postcss-purgecss';
// https://vitejs.dev/config/
export default defineConfig({
...
css: {
postcss: {
plugins: [
purgecss({
content: [
'./index.html',
'./src/**/*.{vue,js,ts}'
],
variables: true,
safelist: {
// Keep leaflet classes
standard: [/leaflet-/]
}
})
]
}
}
}); Given that vite has deprecated CJS, it looks like the only option now is to embed the config in |
Beta Was this translation helpful? Give feedback.
I've also just diagnosed this issue with vite and postcss-preset-env. Has there been any fix or work around for this?