Vue引入Bootstrap运行npm run serve出现autoprefixer警告如何解决
问题描述
基于Vue.js开发CRUD应用时,完成Vue、Bootstrap全局安装后,在main.js中引入Bootstrap相关文件,配置代码如下:
import Vue from 'vue' import App from './App.vue' import './registerServiceWorker' import router from './router' import store from './store' import BootstrapVue from 'bootstrap-vue' import 'bootstrap/dist/css/bootstrap.css' import 'bootstrap-vue/dist/bootstrap-vue.css' Vue.use(BootstrapVue) Vue.config.productionTip = false new Vue({ router, store, render: h => h(App) }).$mount('#app')
执行npm run serve命令时,控制台输出1条编译警告:
WARNING Compiled with 1 warning 6:43:27 PM warning in ./node_modules/bootstrap/dist/css/bootstrap.css Module Warning (from ./node_modules/postcss-loader/dist/cjs.js): Warning (2482:3) autoprefixer: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.

原因说明
该警告由Bootstrap与autoprefixer的版本适配问题触发:旧版本Bootstrap中使用了已被废弃的color-adjust简写属性,新版本autoprefixer检测到该属性后,会提示替换为标准属性print-color-adjust。该警告不会影响项目正常编译、运行,也不会造成样式或功能异常。
解决方法
可根据项目实际情况选择以下任意一种方案处理:
- 升级Bootstrap版本
升级Bootstrap到5.3及以上版本,官方已在新版本中修复该属性废弃问题,升级后警告自动消除,执行命令:
若项目使用npm install bootstrap@^5.3.0bootstrap-vue,升级前需确认对应版本兼容的Bootstrap版本范围,避免升级后出现组件样式、功能异常。 - 直接忽略警告
该警告仅为属性废弃提示,无实际负面影响,无需修改任何配置即可正常开发、打包上线。 - 调整browserslist配置规避检测
在项目根目录package.json中添加browserslist配置,指定项目兼容的浏览器范围,避开autoprefixer对该废弃属性的检测,示例配置:
配置完成后重启开发服务,警告即可消失。"browserslist": [ "> 1%", "last 2 versions", "not dead" ]
内容的提问来源于stack exchange,提问作者Mery
相关产品推荐
相关产品推荐

