全局SASS变量不起作用(未定义) - 实时SASS编译器

发布于 2025-02-06 13:04:48 字数 1732 浏览 1 评论 0原文

我正在使用VSCODE扩展名 - Live Sass Compiler (Glenn Marks版本)。除了全局变量之外,当我将它们包含在 app 组件中时,返回未定义的全局变量。 这是我的项目结构:

”在此处输入图像描述”

_variables.scss

@import url("https://fonts.googleapis.com/css2?family=Great+Vibes&display=swap");

$font_logo: "Great Vibes", cursive;
$max_width: 750px;

_defaults.scss

* {
  box-sizing: border-box;
}

body {
  margin:0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans",
    "Droid Sans", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing-: grayscale;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
}

index.scs.scss 我在应用程序中导入的.js。

@import './variables';
@import './defaults';

app.js 导入

import "./styles/index.scss";

什么是有效的?

样式,例如标签,课程等

全球 什么是不起作用的?

_variables.scss 中定义的变量无法正常工作,并给出不确定的错误。

我尝试的是

我安装了Glenn Marks版本的 ,因为不再支持Ritwick Dey的版本。 我试图将@import更改为@USE@USE'path'为。我尝试更改导入文件的顺序。我一直在寻找几个主题的答案,但没有找到答案。

当我导入@import'./ variables';到特定的SCSS文件时,它可以工作,但我只想将此文件仅包含在index.scs.scss中。当我需要变量时,我不想在每个SCSS文件中写下它。

感谢您的帮助!

I'm using VSCode extension - Live Sass Compiler (Glenn Marks version). Everything works well besides global variables which return undefined when I include them in App component.
This is my project structure:

enter image description here

_variables.scss

@import url("https://fonts.googleapis.com/css2?family=Great+Vibes&display=swap");

$font_logo: "Great Vibes", cursive;
$max_width: 750px;

_defaults.scss

* {
  box-sizing: border-box;
}

body {
  margin:0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans",
    "Droid Sans", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing-: grayscale;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
}

and index.scss which I import in App.js.

@import './variables';
@import './defaults';

App.js import

import "./styles/index.scss";

What is working?

Global styling like tags, classes etc. working well so they are loaded correctly

What is not working?

Defined variables in _variables.scss not working and give undefined error.

What I tried?

I installed Glenn Marks version because Ritwick Dey's is not supported anymore.
I tried to change @import to @use and @use 'path' as. I tried changing order of imported files. I was looking for answer in several topics but didn't find an answer.

When I import @import './variables'; to a specific scss file it works but I want to include this file only once in index.scss. I don't want to write it in every scss file when I need variables.

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文