vite中sass警告JS?API過期的原因及解決辦法
1.問題
- 在Vite創(chuàng)建項目中引入Sass彈出The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0
- vite中sass警告JS API過期

- The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0
- 警告提示表明你當前正在使用的 Dart Sass 版本中,舊的 JavaScript API 已經(jīng)被棄用
2.產(chǎn)生原因和解決方法
- 訪問sass官網(wǎng)
由于是vite創(chuàng)建的項目,翻到Bundles部分,通過紅框可以看出Vite仍然默認使用傳統(tǒng)的API,需要通過Vite設(shè)置api為"modern"或"modern-compiler",即可解決

圖片紅框部分翻譯:Vite仍然默認使用傳統(tǒng)的API,但您可以通過將api設(shè)置為"modern"或"modern-compiler"來類似地切換它。請參閱Vite的文檔以了解更多詳細信息。
- 訪問Vite官網(wǎng)

- 在css.preprocessorOptions部分發(fā)現(xiàn)
sass/scss的api默認值為"legacy" - 配置Vite.config.ts文件,即可解決

import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
export default defineConfig({
// 設(shè)置scss的api類型為modern-compiler
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler'
}
}
},
plugins: [ vue(),vueJsx()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
小結(jié)
本文解決在Vite創(chuàng)建的項目中引入Sass時,
- 彈出The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.警告,舊的 JavaScript API 已經(jīng)被棄用
- 通過Sass官網(wǎng)和Vite官網(wǎng)配置api為modern-compiler成功解決
到此這篇關(guān)于vite中sass警告JS API過期的原因及解決辦法的文章就介紹到這了,更多相關(guān)vite sass警告JS API過期內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決vue中post方式提交數(shù)據(jù)后臺無法接收的問題
今天小編就為大家分享一篇解決vue中post方式提交數(shù)據(jù)后臺無法接收的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
vue在App.vue文件中監(jiān)聽路由變化刷新頁面操作
這篇文章主要介紹了vue在App.vue文件中監(jiān)聽路由變化刷新頁面操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08
Vue+Typescript中在Vue上掛載axios使用時報錯問題
這篇文章主要介紹了Vue+Typescript中在Vue上掛載axios使用時報錯問題,本文給大家介紹的非常詳細,具有一定的參考借鑒價值 ,需要的朋友可以參考下2019-08-08

