angular - 构建 Angular 库时防止 SCSS 处理

标签 angular sass components

出于主题性目的,我们希望能够在消费应用程序的 Angular 组件库中更改 SCSS 变量。

是否可以阻止我们的组件库将 SCSS 处理为 CSS?或者有没有更好的方法来实现我们想要的?

最佳答案

SCSS 不是浏览器理解的语言。所以在一天结束时,sccs 将被转换为 CSS。

即使可以,从库中导出 scss 并构建它也是一种非常糟糕的做法。它违反了很多做法。

问题是,无论如何,scss 正在与您的应用程序一起构建。

你可以通过很多方式。您可以按照网络上的众多指南之一在您的应用程序中创建一组主题。 ( check one example here )

或者你可以采用有 Angular Material 的方式。在此处查看他们如何处理主题:angular material themeing

第一个比第二个容易。第二个,假设您在 mixin 中拥有所有样式,并且当您构建它们时,主题相关变量将应用。

// Import library functions for theme creation.
@import '~@angular/material/theming';

// Include non-theme styles for core.
@include mat-core();

// Define your application's custom theme.
$primary: mat-palette($mat-indigo);
$accent:  mat-palette($mat-pink, A200, A100, A400);
$theme: mat-light-theme($primary, $accent);

// Include theme styles for Angular Material components.
@include angular-material-theme($theme);

// Include theme styles for your custom components.
@include candy-carousel-theme($theme);

关于angular - 构建 Angular 库时防止 SCSS 处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58724900/

相关文章:

带有 '@' 符号的 Angular 2 url 构造

angular - http get 请求返回未定义

css - SASS 如何帮助我开发响应式网页设计?

android - 如何在 java 和 xml 中传递自定义组件参数

javascript - 如何从 Angular 服务对 propublica.org 进行 Web API 调用

javascript - Ionic 2/Angular 2 中的 Mapbox 标记单击事件

css - 如何使 Sass mixin 在基层声明非嵌套选择器?

css - gulp任务复制整个文件夹

javascript - react .js : Composing components to create tabs

sass - 如何将 SASS 与 Polymer 一起使用?