vue.js - 如何在 vue 3 vite 中使用 sass 扩展?

标签 vue.js sass vuejs3 vite

例如,我在 app.scss 中导入了 bootstrap,

@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/bootstrap.scss";

如果我这样做,现在在一个组件中,

<style scoped lang="scss">
.text {
  @extend .text-white;
}
</style>

我得到以下错误,

[plugin:vite:css] The target selector was not found.
Use "@extend .text-white !optional" to avoid this error.
  ╷
8 │   @extend .text-white;
  │   ^^^^^^^^^^^^^^^^^^^
  ╵
  src/components/Navbar.vue 8:3  root stylesheet

最佳答案

vite.config.js 中为 CSS 预处理器添加一个选项:

css: {
  preprocessorOptions: {
    scss: {
      additionalData: `@import "bootstrap/scss/bootstrap";`
    }
  }
},

enter image description here

有关更多信息,您可以查看官方文档 https://vitejs.dev/config/#css-preprocessoroptions

关于vue.js - 如何在 vue 3 vite 中使用 sass 扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69130068/

相关文章:

javascript - Vue DevTools 正确更新但浏览器窗口不更新

vue.js - paypal API v2 不支持发货

Laravel 新星 : Build Components

css - Sass Ruby 过渡滤镜效果报错信息

typescript - 如何在 Vue Router v4 中为自定义元字段声明 TypeScript 类型接口(interface)?

vue.js - 如何获取调用函数的组件?

类更改时的 Vue.js css 转换

html - Div 没有向左浮动

sass - 通过 Sass 集成 Laravel 和 Materialise-CSS 的正确方法是什么?

vue.js - 如何在 vue.js 版本 3 中上传文件