Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure Autoprefixer in Angular 7

I'm using autoprefix in Angular 7 Project. But When I open the browser devtools and focus the element with class "simple-content", which has display flex as applied style, there is no expected 'prefixes'. In Angular 4-6 projects, this works ok.

Step 1: Run ng serve Step 2: Open the browser devtools and focus the element with class "simple-content", which has display:flex.

In package.json I have

 {
    "browserslist": [
    "last 1 version",
    "> 1%"
    ]
  }. 

In package-lock.json I have 

    "autoprefixer": {
      "version": "9.4.4",
      "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.4.4.tgz",
      "integrity": "sha512-7tpjBadJyHKf+gOJEmKhZIksWxdZCSrnKbbTJNsw+/zX9+f//DLELRQPWjjjVoDbbWlCuNRkN7RfmZwDVgWMLw==",
      "requires": {
        "browserslist": "^4.3.7",
        "caniuse-lite": "^1.0.30000926",
        "normalize-range": "^0.1.2",
        "num2fraction": "^1.2.2",
        "postcss": "^7.0.7",
        "postcss-value-parser": "^3.3.1"
      },

I tried to enable autoprefixing for flexbox with /* autoprefixer: on */, but no result.

In css file i have

.simple-content {
    display: flex;
}

Expected result :

.simple-content {
  display: -webkit-box;    
  display: -moz-box;      
  display: -ms-flexbox;   
  display: -webkit-flex;   
  display: flex;             
}
like image 339
Yordan Penev Avatar asked Jan 10 '19 11:01

Yordan Penev


People also ask

What is PostCSS and autoprefixer?

PostCSS was developed by Andrey Sitnik, the creator of Autoprefixer. It is a Node. js package developed as a tool to transform all of your CSS using JavaScript, thereby achieving much faster build times than other processors.

What is autoprefixer NPM?

PostCSS plugin to parse CSS and add vendor prefixes to CSS rules using values from Can I Use. It is recommended by Google and used in Twitter and Alibaba. Write your CSS rules without vendor prefixes (in fact, forget about them entirely): ::placeholder { color: gray; } .

Does Sass have autoprefixer?

Autoprefixer can be easily integrated with Sass and Stylus, since it runs after CSS is already compiled. Autoprefixer is based on Rework, a framework for writing your own CSS postproccesors. Rework parses CSS to useful JavaScript structure and exports it back to CSS after your manipulations.


1 Answers

I tried online autoprefixer tool (https://autoprefixer.github.io/) to test the browserlist you used in package.json and observed that it did not generate prefixed css: did not yield prefixed css

On changing the browser list value to last 2 version, it generated autoprefixed css: did generate prefixed css

So your package.json seems fine and you can try it by just updating browser list.

Also FYI, angular cli V7.3.5 added src/browserslist which means you need not to add .browserslistrc or browserslist property to the package.json for angular 7 projects. All you need to do is remove not on last line to support IE 9-11.

like image 78
Kapil Bhagat Avatar answered Oct 23 '22 05:10

Kapil Bhagat