Home Sass Meta meta.module-mixins() Definition
Definition and Usage meta.module-mixins($module) returns a map of every mixin defined in $module—keys are mixin names, values are mixin values . Include them with meta.apply (Dart Sass 1.69+ ). Load with @use "sass:meta".
Official sample idea. After @use "mixins", @include meta.apply(map.get(meta.module-mixins("mixins"), "stretch")) emits the stretch flex rules.
$module matches a namespace.Pass a string matching a @use namespace in the current file (e.g. "mixins"), or a module value.
Map values are not CSS. Include them with @include meta.apply($mixin). Peek at names with map.keys + meta.inspect .
Syntax
Syntax @use "sass:map";
@use "sass:meta";
@use "mixins";
meta.module-mixins($module); //=> map
// Official pattern
.header {
@include meta.apply(
map.get(meta.module-mixins("mixins"), "stretch")
);
}
// Module API — Dart Sass 1.69+ (with meta.apply) Pattern: @use the module → module-mixins for the catalog → map.get / map.has-key → @include meta.apply.
Code
SCSS Examples Examples target Dart Sass 1.69+ with @use "sass:meta". Open View Compiled CSS for verified output (matches official Sass docs samples where shown).
1. Keys 2. apply + stretch 3. Probe 4. Optional 5. Guard Example 1 — List Mixin Names in a Module Inspect map.keys so you can see the catalog without printing mixin values.
@mixin stretch() {
align-items: stretch;
display: flex;
flex-direction: row;
}
@mixin soft-shadow {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
} @use "sass:map";
@use "sass:meta";
@use "mixins";
$mx: meta.module-mixins("mixins");
.probe {
--keys: #{meta.inspect(map.keys($mx))};
} .probe {
--keys: "stretch", "soft-shadow";
} How It Works @use "mixins" loads the partial.module-mixins returns the map.map.keys lists the names.inspect peeks at them for learning / debug.Example 2 — Official map.get + meta.apply Pick stretch from the map and include it on .header.
@use "sass:map";
@use "sass:meta";
@use "mixins";
.header {
@include meta.apply(
map.get(meta.module-mixins("mixins"), "stretch")
);
} .header {
align-items: stretch;
display: flex;
flex-direction: row;
} How It Works map.get picks the stretch mixin value.meta.apply includes it into the selector.CSS emits the flex stretch rules.Matches the official Sass docs CSS output.Example 3 — Count and Probe Keys Combine list.length with map.has-key for a quick inventory.
@use "sass:list";
@use "sass:map";
@use "sass:meta";
@use "mixins";
$mx: meta.module-mixins("mixins");
.count {
--n: #{list.length(map.keys($mx))};
--has-stretch: #{map.has-key($mx, "stretch")};
--has-nope: #{map.has-key($mx, "nope")};
} .count {
--n: 2;
--has-stretch: true;
--has-nope: false;
} How It Works _mixins.scss exports two mixins.list.length counts the keys → 2.has-key finds stretch.Unknown names return false.Example 4 — Optional Mixin Include Include a helper only when the catalog contains it.
@use "sass:map";
@use "sass:meta";
@use "mixins";
$mx: meta.module-mixins("mixins");
.card {
@if map.has-key($mx, "soft-shadow") {
@include meta.apply(map.get($mx, "soft-shadow"));
}
padding: 1rem;
} .card {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
padding: 1rem;
} How It Works has-key confirms soft-shadow.meta.apply includes it.padding always runs.Remove the mixin and the card still compiles with padding only.Example 5 — Guard Before meta.apply Check map.has-key so optional plugin names fail safely.
@use "sass:map";
@use "sass:meta";
@use "mixins";
$mx: meta.module-mixins("mixins");
$name: "stretch";
.row {
@if map.has-key($mx, $name) {
@include meta.apply(map.get($mx, $name));
} @else {
display: block;
}
} .row {
align-items: stretch;
display: flex;
flex-direction: row;
} How It Works $name is looked up in the catalog.True path applies the mixin value.Missing names take the @else fallback.Safer for plugin-style dynamic includes. Edge Cases & Pitfalls Most module-mixins bugs are wrong namespace strings or forgetting meta.apply.
namespace String must match @use After @use "mixins" as mx, pass "mx", not "mixins".
apply Map values need meta.apply You cannot @include a map entry directly—resolve with map.get, then apply.
guard Check before optional applies Use map.has-key (or mixin-exists ) before map.get + apply.
vs Functions use module-functions Dynamic functions return values via module-functions + meta.call.
Toolchain
Sass Support Prefer the module form with Dart Sass 1.69+ (for meta.apply).
API Status meta.module-mixins()Dart Sass via @use "sass:meta" Return type Map (name → mixin value) Include with @include meta.apply($mixin) (1.69+)LibSass / Ruby Sass Not available
Compile with the Dart Sass CLI .
Remember
Key Takeaways Returns a map of every mixin in a loaded module.
Include with map.get + meta.apply (official pattern).
$module matches @use namespace in the current file.
Dart Sass 1.69+ for apply on mixin values.
One line: to list every mixin in a @use module, use meta.module-mixins($module).
Practice
Compile Notes Practical checklist:
1. @use "sass:meta" (+ "sass:map")
2. @use "your-module"
3. $mx: meta.module-mixins("your-module")
4. map.get / map.has-key / map.keys
5. @include meta.apply($mixin) to emit CSS Frequently Asked Questions What does Sass meta.module-mixins() do? meta.module-mixins($module) returns a map of every mixin defined in that @use module—keys are mixin names, values are mixin values you include with meta.apply.
What must $module be? A string matching the namespace of a @use rule in the current file—for example "mixins" after @use "mixins". It can also be a module value.
How do I include a mixin from the map? Official pattern: @include meta.apply(map.get(meta.module-mixins("mixins"), "stretch")). map.get picks the mixin value; meta.apply includes it.
How is it different from meta.mixin-exists? mixin-exists answers yes/no for one name. module-mixins returns the whole catalog of mixins in a module as a map.
How is it different from meta.get-mixin? get-mixin looks up one mixin by name. module-mixins returns all mixins in a module at once—handy for registries, loops, and map.has-key guards.
Which compilers support it? Dart Sass 1.69+ (needed for meta.apply on mixin values). LibSass and Ruby Sass do not. Prefer current Dart Sass.
CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion