处理报错 Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.

在vue3+vite项目中,使用低sass版本低于2.0.0的,会有上面这个警告

运行项目,会出现下面警告:

下面处理警告,

方法一:

vite.config.[js/ts]. 文件中

export default defineConfig({  css: {    preprocessorOptions: {      // 如果'modern-compiler'不管用,可换成"modern"      scss: {        api: 'modern-compiler' // or "modern"      }    }  }})

方法二:

vite.config.[js/ts]. 文件中

//vite.config.tsexport default defineConfig({  //..other config  css: {    preprocessorOptions: {      scss: {        silenceDeprecations: ["legacy-js-api"],      },    },  },})

注意,在方法二可以和 指定scss公用文件api共存,方法一的不行

在使用方法二,还可以共存scss公用文件api(additionalData),如下:

//vite.config.tsexport default defineConfig({  //..other config  css: {    preprocessorOptions: {        scss: {          additionalData: '@import "./src/assets/scss/var.scss";', // 公用的scss属性文件          silenceDeprecations: ["legacy-js-api"], // 去除警告提示 Deprecation Warning...        }      },  },})

评论
暂无评论

登录后可发表评论

点击登录