@warn
该@warn
规则就是为此而设计的。它被编写 @warn <expression>
并为用户打印表达式的值(通常是一个字符串),以及指示如何调用当前mixin或函数的堆栈跟踪。但是,与@error
规则不同的是,它不会完全阻止Sass。
SCSS 语法
$known-prefixes: webkit, moz, ms, o;
@mixin prefix($property, $value, $prefixes) {
@each $prefix in $prefixes {
@if not index($known-prefixes, $prefix) {
@warn "Unknown prefix #{$prefix}.";
}
-#{$prefix}-#{$property}: $value;
}
#{$property}: $value;
}
.tilt {
// Oops, we typo'd "webkit" as "wekbit"!
@include prefix(transform, rotate(15deg), wekbit ms);
}
Sass语法
$known-prefixes: webkit, moz, ms, o
@mixin prefix($property, $value, $prefixes)
@each $prefix in $prefixes
@if not index($known-prefixes, $prefix)
@warn "Unknown prefix #{$prefix}."
-#{$prefix}-#{$property}: $value
#{$property}: $value
.tilt
// Oops, we typo'd "webkit" as "wekbit"!
@include prefix(transform, rotate(15deg), wekbit ms)
CSS 输出
.tilt {
-wekbit-transform: rotate(15deg);
-ms-transform: rotate(15deg);
transform: rotate(15deg);
}
警告和堆栈跟踪的确切格式因实现而异。这是Dart Sass中的样子:
Warning: Unknown prefix wekbit.
example.scss 6:7 prefix()
example.scss 16:3 root stylesheet