Webpack和Bootstrap 4 mixins和功能出现问题。
sass | css加载程序:
{
test: /\.(sa|sc|c)ss$/,
use: [
// fallback to style-loader in development
// which creates style nodes from JS strings (IE: imports)
process.env.NODE_ENV === 'development' ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
includePaths: ['node_modules']
}
}
]
}
导入为:
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/print";
@import "bootstrap/scss/reboot";
@import "bootstrap/scss/type";
@import "bootstrap/scss/images";
@import "bootstrap/scss/code";
@import "bootstrap/scss/grid";
@import "bootstrap/scss/tables";
@import "bootstrap/scss/forms";
@import "bootstrap/scss/buttons";
@import "bootstrap/scss/transitions";
@import "bootstrap/scss/dropdown";
@import "bootstrap/scss/button-group";
@import "bootstrap/scss/input-group";
@import "bootstrap/scss/custom-forms";
@import "bootstrap/scss/nav";
@import "bootstrap/scss/navbar";
@import "bootstrap/scss/card";
@import "bootstrap/scss/breadcrumb";
@import "bootstrap/scss/pagination";
@import "bootstrap/scss/badge";
@import "bootstrap/scss/jumbotron";
@import "bootstrap/scss/alert";
@import "bootstrap/scss/progress";
@import "bootstrap/scss/media";
@import "bootstrap/scss/list-group";
@import "bootstrap/scss/close";
@import "bootstrap/scss/modal";
@import "bootstrap/scss/tooltip";
@import "bootstrap/scss/popover";
@import "bootstrap/scss/carousel";
@import "bootstrap/scss/utilities";
除了mixin和函数,一切似乎都很好用。
例如,color: color("purple");
可以很好地工作并放置适当的颜色,但是简单的<span className="badge badge-green ml-2">badge here</span>
会加载徽章的基本样式,而不会加载绿色的颜色变体。
没有任何类型的错误,所以我不确定发生了什么。
答案 0 :(得分:1)
您是否在$theme-colors
引导变量中定义了颜色变体“绿色”?
默认情况下,只有以下选项(从bootstrap/_variables.scss
复制):
$theme-colors: () !default;
// stylelint-disable-next-line scss/dollar-variable-default
$theme-colors: map-merge(
(
"primary": $primary,
"secondary": $secondary,
"success": $success,
"info": $info,
"warning": $warning,
"danger": $danger,
"light": $light,
"dark": $dark
),
$theme-colors
);
$theme-color
变量被所有组件用于这样的颜色修改器(以bootstrap/_badge.scss
为例,以徽章组件为例):
@each $color, $value in $theme-colors {
.badge-#{$color} {
@include badge-variant($value);
}
}
因此,如果您要使用颜色变体“绿色”,则必须先将其注册到$theme-colors
变量中,如下所示(无论您覆盖默认的引导变量):
$theme-colors: (
"green": #00ff00
);
更多信息可以通过引导程序本身在徽章组件的文档(https://getbootstrap.com/docs/4.1/components/badge/)和主题颜色的文档(https://getbootstrap.com/docs/4.1/getting-started/theming/#theme-colors)中找到。