首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何导入scss变量取决于包含的混频。

如何导入scss变量取决于包含的混频。
EN

Stack Overflow用户
提问于 2019-08-07 17:02:36
回答 1查看 99关注 0票数 1

在我的角度计划中,我有以下结构:

代码语言:javascript
复制
- modules
 -- foo-module
   -- foo-comp
- assets
 -- fonts
   -- Open_Sans
      ....
- scss
 -- partials
   -- _fontface.scss
   -- _variables.scss
 styles.scss

styles.scss:

代码语言:javascript
复制
@import "./partials/variables";

* {
  margin:  0;
  padding: 0;
}

body{
    background-color: $color;
    font-family: $font-face;
}

_variables.scss:

代码语言:javascript
复制
@import "./fontface";

@include font-face(OpenSans, "../fonts/Open_Sans/OpenSans-Regular", 500, normal, ttf);

$font-face: OpenSans, sans-serif;
$color: yellow;

_fontface.scss:

代码语言:javascript
复制
    // =============================================================================
// String Replace
// =============================================================================

@function str-replace($string, $search, $replace: "") {
    $index: str-index($string, $search);

    @if $index {
        @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
    }

    @return $string;
}

// =============================================================================
// Font Face
// =============================================================================

@mixin font-face($name, $path, $weight: null, $style: null, $exts: eot woff2 woff ttf svg) {
    $src: null;

    $extmods: (
        eot: "?",
        svg: "#" + str-replace($name, " ", "_")
    );

    $formats: (
        otf: "opentype",
        ttf: "truetype"
    );

    @each $ext in $exts {
        $extmod: if(map-has-key($extmods, $ext), $ext + map-get($extmods, $ext), $ext);
        $format: if(map-has-key($formats, $ext), map-get($formats, $ext), $ext);
        $src: append($src, url(quote($path + "." + $extmod)) format(quote($format)), comma);
    }

    @font-face {
        font-family: quote($name);
        font-style: $style;
        font-weight: $weight;
        src: $src;
    }
}

comp.scss:

@import‘./变量’;

现在,我想在我的comp.scss中使用作为导入。所以看起来不太可能,因为@include font-face(OpenSans, "../fonts/Open_Sans/OpenSans-Regular", 500, normal, ttf);这个混音有一个url不依赖于comp.scss url,所以我有一个相应的错误。而且它在style.scss ( ../ url的原因)中看起来不错。

为了将来使用多种字体,我需要这个全局变量$字体面板,并且我想把它们存储在一个地方。

EN

回答 1

Stack Overflow用户

发布于 2019-08-07 17:13:36

因为角6似乎可以与~一起使用绝对导入

代码语言:javascript
复制
@include font-face(OpenSans, "~src/assets/fonts/Open_Sans/OpenSans-Regular", 500, normal, ttf);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57399234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档