我是Angular的新手,来自Ember社区。尝试使用新的基于Ember-CLI的Angular-CLI。
我需要知道在一个新的Angular项目中处理SASS的最佳方法。我尝试使用Ember-CLI -sass回购,看看它是否能正常运行,因为Angular-CLI的许多核心组件都是在Ember-CLI模块上运行的。
它没有工作,但比再次不确定,如果我只是配置错误的东西。
另外,在新的Angular项目中组织样式的最佳方法是什么?如果能将sass文件与组件放在同一个文件夹中就太好了。
我是Angular的新手,来自Ember社区。尝试使用新的基于Ember-CLI的Angular-CLI。
我需要知道在一个新的Angular项目中处理SASS的最佳方法。我尝试使用Ember-CLI -sass回购,看看它是否能正常运行,因为Angular-CLI的许多核心组件都是在Ember-CLI模块上运行的。
它没有工作,但比再次不确定,如果我只是配置错误的东西。
另外,在新的Angular项目中组织样式的最佳方法是什么?如果能将sass文件与组件放在同一个文件夹中就太好了。
当前回答
步骤1。使用npm安装bulma包
npm install --save bulma
步骤2。开放的角。Json和更新以下代码
...
"styles": [
"node_modules/bulma/css/bulma.css",
"src/styles.scss"
],
...
就是这样。
为了方便地公开Bulma的工具,将stylePreprocessorOptions添加到angular.json中。
...
"styles": [
"src/styles.scss",
"node_modules/bulma/css/bulma.css"
],
"stylePreprocessorOptions": {
"includePaths": [
"node_modules",
"node_modules/bulma/sass/utilities"
]
},
...
查找 + 角度 6
其他回答
针对Angular 6+的更新
新项目
当用Angular CLI生成一个新项目时,将css预处理器指定为
使用SCSS语法 Ng新的ssy-project——style=scss 使用SASS语法 Ng新的时髦项目——style=sass
更新现有项目
通过运行在现有项目上设置默认样式
使用SCSS语法 Ng config schematics.@schematics/angular:组件。styleext scss 使用SASS语法 Ng config schematics.@schematics/angular:组件。styleext sass 上面的命令将更新你的工作空间文件(angular.json) “图表”:{ “@schematics /角:组件":{ :“styleext scss” } }
其中styleext可以是SCSS或sass根据选择。
博士TL; 注意:在Angular 9及以后的版本中,styleext被重命名为style Angular 9 & 9+在创建一个新项目时 对于现有的: ng图表.@schematics /角:组件。scss风格 对于Angular 2 - Angular 8: 对于一个现有的项目:ng config schematics.@schematics/angular:component。styleext scss
详细的回答
Angular 9 & 9+:
通过Angular CLI
ng config schematics.@schematics/angular:component.style scss
直接在angular.json中:
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
}
对于旧版本
通过Angular CLI:
ng config schematics.@schematics/angular:component.styleext scss
直接在angular.json中:
注意:查找angular-cli。Json版本大于6。对于版本6和6+,该文件已被重命名为angular.json
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
}
注:原来的SO答案可以在这里找到
下面的代码应该在angular CLI 6项目中工作。例如,如果你得到:
Get /set已弃用,改用config命令。
npm install node-sass --save-dev
然后(确保您更改了项目名称)
ng config projects.YourPorjectName.schematics.@schematics/angular:component.styleext sass
要获得默认项目名,请使用:
ng config defaultProject
然而: 如果你把你的项目从<6迁移到angular 6,很有可能配置不会在那里。在这种情况下,你可能会得到:
无效的JSON字符:“s”在0:0
因此需要手动编辑angular。Json是必需的。
你会希望它看起来像这样(注意styleex属性):
...
"projects": {
"Sassy": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
}
...
对我来说,这似乎是一个过于复杂的模式。¯_()_/¯
你现在必须去改变你所有的css/less文件为scss和更新组件等任何引用,但你应该很好去。
步骤1。使用npm安装bulma包
npm install --save bulma
步骤2。开放的角。Json和更新以下代码
...
"styles": [
"node_modules/bulma/css/bulma.css",
"src/styles.scss"
],
...
就是这样。
为了方便地公开Bulma的工具,将stylePreprocessorOptions添加到angular.json中。
...
"styles": [
"src/styles.scss",
"node_modules/bulma/css/bulma.css"
],
"stylePreprocessorOptions": {
"includePaths": [
"node_modules",
"node_modules/bulma/sass/utilities"
]
},
...
查找 + 角度 6
我注意到在移动到scss文件时一个非常烦人的陷阱!!在app.component.ts中,必须从简单的:styleUrls: [' app.ponent .scss']转移到styleUrls: ['./ app.ponent .scss'] (add ./)
ng在生成新项目时这样做,但在创建默认项目时似乎不这样做。如果在ng构建过程中看到resolve错误,请检查此问题。我只花了1个小时。