Hi I created the react app using npm create vite and I tried to integrate autoprefixer but it's not working.
vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import autoprefixer from 'autoprefixer';
export default defineConfig({
plugins: [react()],
css: {
postcss: {
plugins: [autoprefixer()],
},
},
});
package.json
"devDependencies": {
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.1.0",
"autoprefixer": "^10.4.8",
"postcss": "^8.4.16",
"sass": "^1.54.9",
"vite": "^3.1.0"
},
"browserslist": [ "last 2 versions", "not dead" ]
I tried creating a postcss.config.js and it didn't worked either.
postcss.config.js
import autoprefixer from 'autoprefixer';
export const plugins = {
plugins: [autoprefixer()],
};
Would be great if anyone can help me!
Vite appears to use
postcss-load-configfor its configuration.I solved this with
.postcssrc.jsonand abrowserslistroot key inpackage.json.First install autoprefixer
npm install -D autoprefixerpostcssandpostcss-load-configare included with viteNo additional config needed in
vite.config.js, just the default:.postcssrc.jsonSet up browserslist with one of the recommended options
package.jsonResult:
index.cssCompiles to: