Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 使用带有angular11的AutoRefixer_Css_Angular_Sass - Fatal编程技术网

Css 使用带有angular11的AutoRefixer

Css 使用带有angular11的AutoRefixer,css,angular,sass,Css,Angular,Sass,我正在将angular11与SCSS一起使用。例如,我有以下课程: .freeSpace { flex: 1; display: flex; align-items: flex-end; width: 100%; max-width: 600px; } 但是,当我执行ng build--prod时,它不会转向: .freeSpace { -webkit-box-flex: 1; -ms-flex: 1; f

我正在将angular11与
SCSS
一起使用。例如,我有以下课程:

.freeSpace {
    flex: 1;
    display: flex;
    align-items: flex-end;
    width: 100%;
    max-width: 600px;
}
但是,当我执行
ng build--prod时,它不会转向:

.freeSpace {
    -webkit-box-flex: 1;
        -ms-flex: 1;
            flex: 1;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: end;
        -ms-flex-align: end;
            align-items: flex-end;
    width: 100%;
    max-width: 600px;
}
如何强制angular使用AutoRefixer

我的
angular.json
文件:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "we19-app": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss",
          "skipTests": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "../backend/angular",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "we19-app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "we19-app:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "we19-app:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "we19-app:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "we19-app:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "we19-app"
}
我希望我的最终
scss
文件看起来像前缀器。 当我在浏览器中打开我的应用程序时,会显示“常规”(未转换为autoprefixer代码)scss代码

另外,当我手动将以下内容附加到我的SCS时:

.freeSpace {
    -webkit-box-flex: 1;
        -ms-flex: 1;
            flex: 1;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: end;
        -ms-flex-align: end;
            align-items: flex-end;
    width: 100%;
    max-width: 600px;
}
当我执行
ng build--prod
并在浏览器中查看应用程序时,所有这些“额外”SCS(例如
display:-ms flexbox
)都会被忽略

My.browserslistrc:

# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support

# You can see what browsers were selected by your queries by running:
#   npx browserslist

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.
如果选中,您将看到它仅支持最新浏览器


因此,如果你构建你的应用程序,它只会添加必要的前缀。如果选中,您将看到所有当前浏览器都支持
display:flex
<代码>显示:-ms框
仅受IE10支持,而angular不支持。因此,用不必要的前缀填充CSS是没有意义的。这就是它被过滤掉的原因。

您可以如下修改
.browsslistrc
文件

Safari 6
IE 10
这将导致以下css

.freeSpace {
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: end;
    -ms-flex-align: end;
    align-items: flex-end;
    width: 100%;
    max-width: 600px;
}

为什么要构建angular应用程序并为无法运行angular应用程序的浏览器创建CSS(
-ms flex
仅由IE10使用,
-webkit box
由chrome版本~20使用)这些浏览器无法运行angular应用程序,他们不了解其Javascript。所以没有理由把它放在你的CSS中。我想支持移动原生应用。简单地说,当我在Safari中打开应用程序时,它缺少
display:-webkit框
,因此我没有flex,但为什么angular不支持
Safari
browser?Safari理解
display:flex
根据我发布的链接,它很好。您需要safari的哪个版本的前缀?那么我是否应该用
safari 6
替换
上两个safari主要版本
?是的,只需将
而不是IE 11
替换为
IE 10
,将
上两个safari主要版本
替换为
safari 6