vue 打包时报错 Syntax Error: SassError: Undefined variable. ╷ 314 $sideBarWidth或者 @import “@/variables.

当遇到Vue打包报错涉及$sideBarWidth和变量导入时,可能是由于sass-loader版本问题。解决需配置vue.config.js以支持scss变量,同时注意node-sass版本对应loader选项的变化。

vue打包时报错     $sideBarWidth或者 @import "@/variables.

产生原因可能是因为sass-loader 版本过高,config 配置发生变化

解决方法:

配置vue.config.js文件,使得全局都能使用scss变量,但是node版本对应的node-sass版本也不同,请选择对应的node-sass版本

sass-loader v8
该 data 选项已重命名为 prependData 选项

sass-loader v9.0
prependData 选项已被删除,取而代之的是 additionalData 选项

node-sass对应的sass-loader版本也不同

<template> <div :class="{ 'has-logo': showLogo }" :style="{ backgroundColor: settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground, }" > <logo v-if="showLogo" :collapse="isCollapse" /> <el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper"> <el-menu :default-active="activeMenu" :collapse="isCollapse" :background-color=" settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground " :text-color=" settings.sideTheme === 'theme-dark' ? variables.menuColor : variables.menuLightColor " :unique-opened="true" :active-text-color="settings.theme" :collapse-transition="false" mode="vertical" > <sidebar-item v-for="(route, index) in sidebarRouters" :key="route.path + index" :item="route" :base-path="route.path" /> </el-menu> </el-scrollbar> </div> </template> <script> import { mapGetters, mapState } from "vuex"; import Logo from "./Logo"; import SidebarItem from "./SidebarItem"; import variables from "@/assets/styles/variables.scss"; export default { components: { SidebarItem, Logo }, computed: { ...mapState(["settings"]), ...mapGetters(["sidebarRouters", "sidebar"]), activeMenu() { const route = this.$route; const { meta, path } = route; // if set path, the sidebar will highlight the path you set if (meta.activeMenu) { return meta.activeMenu; } return path; }, showLogo() { return this.$store.state.settings.sidebarLogo; }, variables() { return variables; }, isCollapse() { return !this.sidebar.opened; }, }, }; </script> <style scoped lang="scss"> // ================================================================ // 🌟 悬浮 & 点击特效:霓虹流动 + 发光扩散 // ================================================================ .el-menu--vertical { background: $base-menu-background !important; border-right: none; overflow: hidden; padding: 10px 0; .el-menu-item, .el-submenu__title { color: $base-menu-color; height: 50px !important; line-height: 50px !important; font-size: 14px; font-weight: 500; transition: all 0.3s cubic-bezier(0.25, 0.8, 0.5, 1); margin: 6px 8px; border-radius: 12px; position: relative; overflow: hidden; background: transparent; // 默认内边距 padding-left: 20px !important; // 💫 Hover 悬浮特效 &:hover { color: #ffffff !important; background: $base-sub-menu-hover !important; transform: translateX(4px); box-shadow: 0 4px 16px rgba(42, 74, 128, 0.35); } // 🔆 激活状态:发光边框 + 扩散光晕 &.is-active { color: #ffffff !important; background: $base-sub-menu-hover !important; border: 1px solid #5d8bfb; box-shadow: 0 0 8px #5d8bfb, 0 0 16px rgba(93, 139, 251, 0.4); transform: scale(1.02); outline: none; // 可选:添加微小脉冲动画(需额外 keyframe) animation: pulse 2s infinite alternate; } } // 嵌套菜单缩进 .nest-menu .el-menu-item { padding-left: 50px !important; } } // 🌀 @keyframes: 脉冲发光动画(可选) @keyframes pulse { 0% { box-shadow: 0 0 8px #5d8bfb, 0 0 16px rgba(93, 139, 251, 0.4); } 100% { box-shadow: 0 0 12px #79a7ff, 0 0 24px rgba(93, 139, 251, 0.6); } } // ================================================================ // 🖼️ Logo 区域美化建议(配合使用) // ================================================================ .sidebar-logo-container { text-align: center; padding: 20px 0; .sidebar-logo-link { color: $base-logo-title-color; font-size: 18px; font-weight: bold; letter-spacing: 1px; text-shadow: 0 0 6px rgba(255, 255, 255, 0.5); } } </style> error in ./src/layout/components/Sidebar/index.vue?vue&type=style&index=0&id=33ec43fc&scoped=true&lang=scss Syntax Error: SassError: Undefined variable. 81 │ background: $base-menu-background !important; │ ^^^^^^^^^^^^^^^^^^^^^ ╵ src\layout\components\Sidebar\index.vue 81:15 root stylesheet @ ./node_modules/vue-style-loader??ref--8-oneOf-1-0!./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/layout/components/Sidebar/index.vue?vue&type=style&index=0&id=33ec43fc&scoped=true&lang=scss 4:14-495 15:3-20:5 16:22-503 @ ./src/layout/components/Sidebar/index.vue?vue&type=style&index=0&id=33ec43fc&scoped=true&lang=scss @ ./src/layout/components/Sidebar/index.vue @ ./src/layout/components/index.js @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/layout/index.vue?vue&type=script&lang=js @ ./src/layout/index.vue?vue&type=script&lang=js @ ./src/layout/index.vue @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://192.168.1.15:80&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
09-29
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值