Replies: 1 comment
-
这个问题解决了吗? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
vite+vue项目中,在vue文件里引入并使用sass中定义的变量;
例如:styles/variables.module.scss文件内容如下:
若在vue文件中去使用该sass文件定义的变量:
1、在style中引入:
@import '[@/styles/variables.module.scss']();
2、在script中引入:
注:在script中引入scss时,scss的文件名改成了<文件名>.module.scss
这样就可以同时在script和style中引入后使用了。
但是vite.config.ts中可以全局加载scss文件,配置如下:
这样配置后,在vue文件的style中不需要使用@import引入,就可以直接使用scss中定义的变量。
但是,在vue的script块中是无法直接使用scss里定义的变量的。此时,在script中加入:
import variables from '@/styles/variables.module.scss'
执行就会报如下错误:“模块已经被加载”。
**[vite] Internal server error: Module loop: this module is already being loaded.**
请教:
如何在vite.config中统一配置并全局加载,以达到在vue的script和style块中都可以直接使用scss里定义的变量呢?
感谢指点!
我的系统信息如下:
Beta Was this translation helpful? Give feedback.
All reactions