12

I'm using create-react-app and I'm using ".scss" files to style the app, and according to the documentation, autoprefixer should work automatically ... https://facebook.github.io/create-react-app/docs/post-processing-css

Here's my "index.scss" file ...

/* autoprefixer grid: on */
@import "./app/css/reset";
@import "./app/css/variables";
@import "./app/css/mixins";
@import "./app/css/global";
@import "./app/css/form";

It just imports a bunch of other ".scss" files.

And here's the "index.js" file ...

import React from "react";
import ReactDOM from "react-dom";
import * as serviceWorker from "./serviceWorker";
import { BrowserRouter as Router } from "react-router-dom";
import { Provider } from "react-redux";
import "./index.scss";
import App from "./App";
import { configureStore } from "./app/store/configureStore";


const store = configureStore();

ReactDOM.render(
    <Provider store={store}>
        <Router>
            <App />
        </Router>
    </Provider>,
    document.getElementById("root")
);

serviceWorker.unregister();

And here's the [browserslist] in package.json file ...

"browserslist": [
    "last 1 version",
    "> 1%",
    "maintained node versions",
    "not dead"
]

What am I doing wrong here? Whenever I inspect the CSS I can't see any autoprefixing happening.

Ruby
  • 2,207
  • 12
  • 42
  • 71

3 Answers3

21

Your browserlist setting is really modern. This means many of the css prefixes are no longer necessary. Try something like

"browserslist": [
    "since 2010" // support all browsers & versions released since 2010
]

and you should start to see autoprefixer kicking in.

Here's the list of queries you can make.

Derek Nguyen
  • 11,294
  • 1
  • 40
  • 64
0

In my case, the accepted answer worked only for running the development server using yarn start.

Autoprefixer did not add the grid prefixes for the production build, despite having ie 11 in the browserslist and the comment /* autoprefixer grid: autoplace */ in the scss files.

So I had to add the environment variable AUTOPREFIXER_GRID=autoplace when running yarn run build.

I could get the grid autoprefixing to work either using command line:

AUTOPREFIXER_GRID=autoplace yarn run build

OR

updating package.json:

"scripts": {
  "start": "react-scripts start",
  "build": "AUTOPREFIXER_GRID=autoplace react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject"
}

create-react-app version: 3.4.1.

HelloWorld101
  • 3,878
  • 2
  • 34
  • 47
  • To enable autoprefixing for grid just add this line /* autoprefixer grid: autoplace */ to the top of your css/scss file see https://create-react-app.dev/docs/post-processing-css/. Should do the job :) – o-faro Aug 27 '20 at 13:06
  • 1
    Thank you! I had exactly the same issue.. I've `/* autoprefixer grid: autoplace */` and all works fine on dev but doesn't work in prod build.. this env variable did the fix :) – GSerjo Jan 26 '21 at 16:04
0
/* autoprefixer grid: autoplace */

Did not work for the production build in create-react-app, since it gets removed in compressed mode.

Solution:

/*! autoprefixer grid: autoplace */
Mordechai
  • 15,437
  • 2
  • 41
  • 82