admin管理员组文章数量:1336632
I'm still new to the @use
and @forward
rules in scss, so I may be misunderstanding a bit and would appreciate some help.
I have a file that sets up a configuration for a vendor library: uswds-theme.scss
@use 'uswds-core' with (
$theme-show-notifications: false,
// there will be a LOT of configurations in here
);
Then, that file is referenced in the main vendor imports: uswds.scss
@forward "./uswds-theme"; // this is mine
// other vendor stuff, e.g.
@forward "uswds-global";
@forward "uswds-helpers";
@forward "uswds-typography";
// ...
Now, I have some other custom components that I want to create in their own files, which is a combination of custom code and leveraging variables/mixins/functions from uswds-core:
@use 'uswds-core';
.custom-component {
background: color('black');
padding: 16px 0;
// ...
}
The problem is, this last @use
does not include the configuration from uswds-theme.scss, so it's not referencing the same configured variables. I don't want to re-configure it each time I @use
it, because that would be a nightmare to keep consistent. How do I structure this so that:
- There is one copy of the configuration
- I can leverage the variables
- Components can be in their own separate files
I'm still new to the @use
and @forward
rules in scss, so I may be misunderstanding a bit and would appreciate some help.
I have a file that sets up a configuration for a vendor library: uswds-theme.scss
@use 'uswds-core' with (
$theme-show-notifications: false,
// there will be a LOT of configurations in here
);
Then, that file is referenced in the main vendor imports: uswds.scss
@forward "./uswds-theme"; // this is mine
// other vendor stuff, e.g.
@forward "uswds-global";
@forward "uswds-helpers";
@forward "uswds-typography";
// ...
Now, I have some other custom components that I want to create in their own files, which is a combination of custom code and leveraging variables/mixins/functions from uswds-core:
@use 'uswds-core';
.custom-component {
background: color('black');
padding: 16px 0;
// ...
}
The problem is, this last @use
does not include the configuration from uswds-theme.scss, so it's not referencing the same configured variables. I don't want to re-configure it each time I @use
it, because that would be a nightmare to keep consistent. How do I structure this so that:
- There is one copy of the configuration
- I can leverage the variables
- Components can be in their own separate files
1 Answer
Reset to default 0Turns out that you can include with
with @forward as well (example on this page: https://sass-lang/documentation/at-rules/forward/#configuring-modules)
So, the solution ended up looking like this:
uswds-theme.scss
@forward 'uswds-core' with (
$theme-show-notifications: false,
// there will be a LOT of configurations in here
);
uswds.scss
@forward "./uswds-theme"; // this is mine
// other vendor stuff, e.g.
@forward "uswds-global";
@forward "uswds-helpers";
@forward "uswds-typography";
// ...
custom-component.scss
@use 'uswds-core' as *;
.custom-component {
background: color('black');
padding: 16px 0;
// ...
}
本文标签: webpackScss use with consistent with parameters across multiple filesStack Overflow
版权声明:本文标题:webpack - Scss @use with consistent `with` parameters across multiple files - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742412262a2470021.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论