我使用angular-cli:1.0.0-beta.19-3 with node:v5.11.1
在我的angular-cli.json文件中,我已将全局样式文件扩展名设置为.scss.
这是我的样式文件.
angular2/src/styles.scss
// Default Font @import url(https://fonts.googleapis.com/css?family=Raleway:300,400,600); // Typography $font-family-sans-serif: "Raleway",sans-serif; $font-size-base: 14px; $line-height-base: 1.6; $text-color: #636b6f; // Import bootstrap @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";
当我尝试导入bootrap-sass模块时,错误吐出,它给出了与glyphicon图标相关的错误.不知道如何解决它.
ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss Module not found: Error: Can't resolve '../fonts/bootstrap/glyphicons-halflings-regular.eot' in '/var/www/angular/src' @ ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss 6:4253-4315 6:4338-4400 @ ./src/styles.scss @ multi styles ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss Module not found: Error: Can't resolve '../fonts/bootstrap/glyphicons-halflings-regular.woff2' in '/var/www/angular2/src' @ ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss 6:4452-4516 @ ./src/styles.scss @ multi styles ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss Module not found: Error: Can't resolve '../fonts/bootstrap/glyphicons-halflings-regular.woff' in '/var/www/angular2/src' @ ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss 6:4549-4612 @ ./src/styles.scss @ multi styles ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss Module not found: Error: Can't resolve '../fonts/bootstrap/glyphicons-halflings-regular.ttf' in '/var/www/angular2/src' @ ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss 6:4644-4706 @ ./src/styles.scss @ multi styles ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss Module not found: Error: Can't resolve '../fonts/bootstrap/glyphicons-halflings-regular.svg' in '/var/www/angular2/src' @ ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss 6:4742-4804 @ ./src/styles.scss @ multi styles
经过一些研究后,我在这里找到了解决方案.
https://github.com/angular/angular-cli/issues/2170
我必须在导入bootstrap sass文件之前设置glyphicons的图标路径.即.
$icon-font-path: '~bootstrap-sass/assets/fonts/bootstrap/'; // Import bootstrap @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";