Sass @use not loading partial

 ̄綄美尐妖づ 提交于 2020-05-12 15:35:38

问题


I'm trying to import a sass partial (_variables.scss) to use in my main stylesheet (global.scss), but I keep getting the Error: Undefined variable. on sass compiling.

Directory structure:

app
└─public
  └─styles
    │  global.css (output for sass compiling is here).
    └─sass
      └─_variables.scss
      └─global.scss

_variables.scss

$font-text: 'lato', sans-serif;

global.scss

@use '_variables';

body {
  font-family: $font-text;
}

Looking at the Sass documentation, I understand to use @use instead of @import (which works) because they are phasing it out.

What am I doing wrong here? Thanks.


回答1:


That's because you are not using Dart Sass which supports this feature.

Also in the documentation you will find:

Only Dart Sass currently supports @use. Users of other implementations must use the @import rule instead.

So use @import until @use is supported.

BTW, If you want to use Dart Sass, just use sass instead of node-sass and require it in the webpack config, like:

// ...
{
  loader: 'sass-loader',
  options: {
    implementation: require('sass')
  }
}
// ...


来源:https://stackoverflow.com/questions/58474760/sass-use-not-loading-partial

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!