Angular SASS (.scss
) 剥离属性。如何防止这种情况发生,以便我可以嵌入重复的属性以实现跨浏览器兼容性?
要复制,请创建一个新的 Angular 7.2 项目
{ "name": "default-app", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "~7.2.0", "@angular/common": "~7.2.0", "@angular/compiler": "~7.2.0", "@angular/core": "~7.2.0", "@angular/forms": "~7.2.0", "@angular/platform-browser": "~7.2.0", "@angular/platform-browser-dynamic": "~7.2.0", "@angular/router": "~7.2.0", "core-js": "^2.5.4", "rxjs": "~6.3.3", "tslib": "^1.9.0", "zone.js": "~0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "~0.13.0", "@angular/cli": "~7.3.9", "@angular/compiler-cli": "~7.2.0", "@angular/language-service": "~7.2.0", "@types/node": "~8.9.4", "@types/jasmine": "~2.8.8", "@types/jasminewd2": "~2.0.3", "codelyzer": "~4.5.0", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~4.0.0", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.1", "karma-jasmine": "~1.1.2", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.4.0", "ts-node": "~7.0.0", "tslint": "~5.11.0", "typescript": "~3.2.2" } }
将“teststyle”类添加到组件中的任何元素。
<div style="text-align:center" class="teststyle">Hello </div> <router-outlet></router-outlet>
在组件对应的.scss文件中应用
.teststyle { background: #a64bf4; background: -webkit-linear-gradient(right, #6ab443, #04a95f, #00d421); background: -o-linear-gradient(right, #6ab443, #04a95f, #00d421); background: -moz-linear-gradient(right, #6ab443, #04a95f, #00d421); background: linear-gradient(right, #6ab443, #04a95f, #00d421); }
角度预处理器会删除除第一个属性和最后一个属性之外的所有内容。 对应的css是这样的。 -webkit-线性梯度、-o-线性梯度和-moz-线性梯度不是转译的css/js文件。这是一个 tarnspilation 问题,而不是浏览器问题。
当我使用直接 css 时,我看到了这一点,这是正确的。
还包括 angular.json
{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "default-app": { "root": "", "sourceRoot": "src", "projectType": "application", "prefix": "app", "schematics": { "@schematics/angular:component": { "style": "scss" } }, "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/default-app", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.app.json", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.scss" ], "scripts": [], "es5BrowserSupport": true }, "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "aot": true, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, "budgets": [ { "type": "initial", "maximumWarning": "2mb", "maximumError": "5mb" } ] } } }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "browserTarget": "default-app:build" }, "configurations": { "production": { "browserTarget": "default-app:build:production" } } }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "default-app:build" } }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.spec.json", "karmaConfig": "src/karma.conf.js", "styles": [ "src/styles.scss" ], "scripts": [], "assets": [ "src/favicon.ico", "src/assets" ] } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "src/tsconfig.app.json", "src/tsconfig.spec.json" ], "exclude": [ "**/node_modules/**" ] } } } }, "default-app-e2e": { "root": "e2e/", "projectType": "application", "prefix": "", "architect": { "e2e": { "builder": "@angular-devkit/build-angular:protractor", "options": { "protractorConfig": "e2e/protractor.conf.js", "devServerTarget": "default-app:serve" }, "configurations": { "production": { "devServerTarget": "default-app:serve:production" } } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": "e2e/tsconfig.e2e.json", "exclude": [ "**/node_modules/**" ] } } } } }, "defaultProject": "default-app" }
Angular 使用 Autoprefixer 添加任何所需的供应商前缀并删除不需要的前缀。基本上您无需担心添加任何内容,因为它们会为您添加。被删除的那些是因为不需要它们。
查看:https://caniuse.com/?search=linear-gradient 使用和支持
-webkit-linear-gradient
仅需要-o-linear-gradient
仅 Opera 11.5 和 Opera mobile 12(2011-2012 发布)需要,全球浏览器的比例为 0%-moz-linear-gradient
仅 Firefox 3.5-15(2010-2012 发布)需要,占浏览器的 0.01%如果您仍然希望/需要在 2018 年推出的 Angular 版本中使用 0% 使用 10 多年的旧浏览器支持 CSS 渐变,您只需添加一个
src/browserslist
文件( 相关问题)您可以在此处了解该文件格式