在我的角度计划中,我有以下结构:
- modules
-- foo-module
-- foo-comp
- assets
-- fonts
-- Open_Sans
....
- scss
-- partials
-- _fontface.scss
-- _variables.scss
styles.scssstyles.scss:
@import "./partials/variables";
* {
margin: 0;
padding: 0;
}
body{
background-color: $color;
font-family: $font-face;
}_variables.scss:
@import "./fontface";
@include font-face(OpenSans, "../fonts/Open_Sans/OpenSans-Regular", 500, normal, ttf);
$font-face: OpenSans, sans-serif;
$color: yellow;_fontface.scss:
// =============================================================================
// 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的原因)中看起来不错。
为了将来使用多种字体,我需要这个全局变量$字体面板,并且我想把它们存储在一个地方。
发布于 2019-08-07 17:13:36
因为角6似乎可以与~一起使用绝对导入
@include font-face(OpenSans, "~src/assets/fonts/Open_Sans/OpenSans-Regular", 500, normal, ttf);https://stackoverflow.com/questions/57399234
复制相似问题