Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Autoprefixer to prefix CSS grid in an Angular 8 project

I have to support IE 11 in an Angular project where we use the latest version of it. I really like to use CSS grid features that IE 11 is capable of. But I can't figure out how to get Autoprefixer work properly.

My problem is quite the same as in another question, but that deals with another version.

I created a minimal test case on Stackblitz.

I configured the browserslist file like so:

> 1%
IE 11

And I included a control comment to enable grid feature of Autoprefixer:

/* autoprefixer grid: on */

(I have done that in both CSS files, the global styles and the component styles)

My expectation with this configuration of browserslist and the control comment in the CSS file is, that Autoprefixer adds display: -ms-grid; to the CSS output. But it doesn't.

like image 578
mwinkelm Avatar asked Jul 18 '19 15:07

mwinkelm


People also ask

How to use gulp auto-prefixer for CSS?

On your command prompt, write following command to install Gulp auto-prefixer locally into your directory. npm install --save-dev gulp-autoprefixer To test this auto-prefixer, we’re going to make CSS file on the same directory with property that needs vendor prefixes like below. Go back to your gulpfile.js, copy and paste the code snippet below.

What is Autoprefixer?

Autoprefixer is a PostCSS plugin which parses your CSS and adds vendor prefixes Autoprefixer CSS online Autoprefixer is a PostCSS plugin which parses your CSS and adds vendor prefixes Loading... Browserslist include comment with configuration to the result Select result

How to use Autoprefixer to translate modern CSS grid syntax in IE?

Autoprefixer can be used to translate modern CSS Grid syntax into IE 10 and IE 11 syntax, but this polyfill will not work in 100% of cases. This is why it is disabled by default. First, you need to enable Grid prefixes by using either the grid: "autoplace" option or the /* autoprefixer grid:...

How do I enable grid prefixing in Autoprefixer?

Add grid: 'autoplace' to the options to turn grid prefixing on: Update: In version 9.4.0 limited autoplacement support was introduced to Autoprefixer. For backwards compatibility reasons, the new recommended setting for enabling grid translations is now grid: 'autoplace'. I have updated all the code snippets to reflect this new recommendation.


1 Answers

I don't know how its config should be in angular CLI. But in Webpack loader it configure like this:

// postcss.config.js

module.exports = {
    plugins: {
        'postcss-preset-env': {
            autoprefixer: {
                grid: 'autoplace'
            },
            browsers: [
                'IE >= 11',
                '> 0.1%'
            ]
        }
    }
};

It is too important to set grid: 'autoplace', not grid: 'on'. In Angular project in package.json you can add AUTOPREFIXER_GRID=autoplace. It will be something like this:

"build": "AUTOPREFIXER_GRID=autoplace ng build",

We recently used grids in one of our project and we also support IE11. And hopefully autoprefixer saved us. So be sure, it will definitely work if you configure it properly.

like image 161
Jahongir Avatar answered Oct 26 '22 13:10

Jahongir