如何设置 index.scss 并将变量、mixins 等的全局样式表导入 Angular 6 库?
Angular CLI 生成一个带有根组件和组件 scss 的库,但是添加或导入到根组件的样式对子组件不可用。默认情况下封装样式是有意义的,但我只是找不到任何关于如何设置它的信息或示例。
可用于此的 angular.json"styles": [...]
路径"projectType": "application"
似乎也不适用于"projectType": "library"
。
在此先感谢您的帮助!
更新:我的项目是使用 angular cli v6.0.5 启动的,遵循本指南:https ://medium.com/@tomsu/how-to-build-a-library-for-angular-apps-4f9b38b0ed11
TL; DR 指南:
ng new my-app --style=scss
ng generate library my-library --prefix ml
这是 angular 6 生成的文件结构:
my-app
projects/
my-library/
src/
lib/
shared/..
widgets/..
my-library.component.ts
my-library.module.ts
sass/
_variables.scss
styles.scss // <<< This is where I want to `@import 'variables';`, and for it to be available in all the components of the "my-library" project.
public_api.ts
src/
app/
app.module.ts // << imports projects/my-library/lib/my-library.module as "my-library".
main.ts
index.scss
index.html
README.md
包版本:
Angular CLI: 6.0.5
Node: 10.2.1
OS: darwin x64
Angular: 6.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.6.5
@angular-devkit/build-angular 0.6.5
@angular-devkit/build-ng-packagr 0.6.5
@angular-devkit/build-optimizer 0.6.5
@angular-devkit/core 0.6.5
@angular-devkit/schematics 0.6.5
@angular/cli 6.0.5
@ngtools/json-schema 1.1.0
@ngtools/webpack 6.0.5
@schematics/angular 0.6.5
@schematics/update 0.6.5
ng-packagr 3.0.0
rxjs 6.2.0
typescript 2.7.2
webpack 4.8.3