Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

taukuk's avatar

How to automatically prefix scss with autoprefix in vite

I have installed postcss and autoprefix in in npm with

npm i autoprefixer && npm i postcss

and my vite.config.js file looks like this:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import react from '@vitejs/plugin-react'
import autoprefixer from 'autoprefixer';

export default defineConfig({
    plugins: [
        react(),
        laravel({
            input: [
                'resources/sass/app.scss',
                'resources/js/index.tsx',
            ],
            refresh: true,
            postcss: {
                plugins: [
                    autoprefixer(),
                ]
            },
        }),
    ],
});

But when I run npm run dev or npm run build the css doesn`t seem to be prefixed. How can I fix this? I have also tried to create a postcss.config.js file like this:

module.exports = {
    plugins: {
        autoprefixer: {}
    }
}

But this also doesn`t work. I have "browserlists": [ "defaults" ] in my package.json

0 likes
2 replies
Tresk's avatar

It's working most likely. Try to change "browserlists": [ "defaults" ] to something like "browserlists": [ "last 2 versions" ] and check.

pittet's avatar

I found that I didn't even need to include autoprefixer, it was doing it automatically, I'm not even sure why/where (scary part)...

After removing browserlist and autoprefixer from my npm, my sass still got prefixed.

npm ERR! No dependencies found matching autoprefixer

Added this to my SCSS file for my tests:

.input-element {
    appearance: none;
}

and it produced with npm run build

.input-element{-webkit-appearance:none;-moz-appearance:none;appearance:none}

Please or to participate in this conversation.