Angular应用程序style.css已导入Roboto字体CSS
@import url('https://fonts.googleapis.com/css?family=Roboto:100,200,300,700');
这在开发版本中工作正常,但对于ng build --prod,
它给出了一个错误,并且字体没有加载到浏览器中:
警告15949:4的无效字体值。
Nodejs: 6.11.4
Npm: 3.10.10
@angular/cli: 1.6.8
"@angular/animations": "^4.3.0",
"@angular/cdk": "2.0.0-beta.12",
"@angular/common": "^4.3.0",
"@angular/compiler": "^4.3.0",
"@angular/core": "^4.4.6",
"@angular/forms": "^4.3.0",
"@angular/http": "^4.3.0",
"@angular/material": "2.0.0-beta.12",
"@angular/platform-browser": "^4.3.0",
"@angular/platform-browser-dynamic": "^4.3.0",
类似的问题发生在我的一个有关Material design icons字体的项目中。
这是我为解决面临的类似问题所做的工作。
--verbose
在构建角度包时添加了参数。
ng build --prod --verbose
在执行上述命令后出现的详细信息中,给了我以下详细信息:
Child mini-css-extract-plugin node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!node_modules/postcss-loader/lib/index.js??extracted!src/styles.css: Entrypoint mini-css-extract-plugin = * chunk {0} * (mini-css-extract-plugin) 10.8 KiB [entry] [rendered]
WARNING in Invalid font values at 1439:706. Ignoring.
上面的详细信息指定了src/styles.css
在开发过程中修改的文件名。因此,我注释了该文件中的所有代码,然后再次运行build命令。和它的工作!
现在我知道问题出在styles.css
哪里,因此我开始将几行代码从内部注释移到外部,然后再次运行命令,看看是否出现警告。
重复这两个步骤超过20次后,WARNING in Invalid font values
出现警告。那就是我如何知道以下代码导致了问题
.mdi:before, .mdi-set { transition: all 0.2s; }
所以我删除了上面的代码,并取消注释同一文件中的所有其余代码styles.css
。现在该警告WARNING in Invalid font values
不再出现,Angular可以完美构建该软件包。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句