I'm using React with ViteJS and SASS, but i have a problem. It seems there is not autoprefixer for CSS/SCSS when i will build the project.
How to add an auto-prefixer with ViteJS and SASS?
I'm using React with ViteJS and SASS, but i have a problem. It seems there is not autoprefixer for CSS/SCSS when i will build the project.
How to add an auto-prefixer with ViteJS and SASS?
Add postcss and autoprefixer: yarn add -D postcss@latest autoprefixer@latest
then add a file postcss.config.js
on your root project directory:
module.exports = {
plugins: {
autoprefixer: {}
}
}
ℹ️ Below is an example of a configuration file vite.config.ts
that includes configuration for postcss.
import { defineConfig } from "vite"
import react from '@vitejs/plugin-react'
import autoprefixer from 'autoprefixer'
export default defineConfig({
plugins: [
react()
],
css: {
postcss: {
plugins: [
autoprefixer({}) // add options if needed
],
}
}
})
And if it still doesn't work please provide a reproducible project.
First, you have to install autoprefixer:
npm i autoprefixer -D
after that, you have to go to your vite.config.ts
and add it there:
import autoprefixer from 'autoprefixer';
export default defineConfig({
plugins: [react()],
css: {
...
postcss: {
plugins: [
autoprefixer
],
}
},
...
});
Install postcss and autoprefixer with:
npm i autoprefixer -D
npm i postcss -D
then config vite:
import { defineConfig } from "vite";
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
import react from '@vitejs/plugin-react'
import autoprefixer from "autoprefixer";
export default defineConfig({
plugins: [react(), cssInjectedByJsPlugin()],
css: {
postcss: {
plugins: [autoprefixer],
},
},
build: {
rollupOptions: {
output: {
manualChunks: undefined,
},
},
},
});
© 2022 - 2024 — McMap. All rights reserved.
npm create vite
but the solution is not working. – Connection