我试图使用带角度cli的SASS。我已经阅读过这些文档,并找到了其他有关设置它的SO q / a ...但它仍然无法构建。
这是我的设置:
角-CLI-build.js
sassCompiler: {
includePaths: ['src/app/styles']
}
的src /应用程序/风格/ master.scss
@import 'folder/variables';
@import 'folder/headers';
的src /应用程序/风格/文件夹/ _variables.scss
$headers-bg: #ababab;
的src /应用程序/风格/文件夹/ _headers.scss
h1 {
background-color: $headers-bg;
}
package.json(每个请求)
{
"name": "my-app",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng server",
"postinstall": "typings install",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/http": "2.0.0-rc.1",
"@angular/platform-browser": "2.0.0-rc.1",
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"@angular/router": "2.0.0-rc.1",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"systemjs": "0.19.26",
"zone.js": "^0.6.12"
},
"devDependencies": {
"angular-cli": "^1.0.0-beta.5",
"codelyzer": "0.0.19",
"ember-cli-inject-live-reload": "^1.4.0",
"jasmine-core": "^2.4.1",
"jasmine-spec-reporter": "^2.4.0",
"karma": "^0.13.15",
"karma-chrome-launcher": "^0.2.3",
"karma-jasmine": "^0.3.8",
"node-sass": "^3.7.0",
"protractor": "^3.3.0",
"ts-node": "^0.5.5",
"tslint": "^3.6.0",
"typescript": "^1.8.10",
"typings": "^0.8.1"
}
}
不幸的是,构建失败了,因为它不知道$ bg是什么。
Build failed.
File: /my-app/tmp/sassplugin-input_base_path-jFTXlfed.tmp/0/
src/app/styles/folder/_more.scss (2)
The Broccoli Plugin: [SASSPlugin] failed with:
Error: Undefined variable: "$headers-bg".
我错过了什么?好像编译器不尊重忽略" _"'文件名的正常行为。
答案 0 :(得分:2)
阅读完源代码后,我发现了这个17天的提交。
我在最初的预感中是对的,它并没有忽略偏见。基本上,你必须告诉sassCompiler你希望它忽略它们。
以下是:
sassCompiler: {
cacheExclude: [/\/_[^\/]+$/]
}
https://github.com/angular/angular-cli/commit/6b45099b6a277ecd7a57f2d2e632bf40af774879
答案 1 :(得分:0)
当你以一种风格导入而不是导入你的变量时,你会有一些倒退的东西......请参阅此示例作为指南......
定义你的变量:
<强> _variables.scss 强>
$bg: #ababab;
使用它们: 的 site.scss 强>
@import '_variables';
body {
background: $bg;
}