从 [vite-plugin-svelte] 中删除 Sveltekits A11y 错误

问题描述 投票:0回答:1

这是 2023 年 7 月 Sveltekit 中的新功能吗?我已经使用过 Sveltekit 多次,并且在新的 sveltekit 项目中打开了一些旧组件,并且收到了很多 Aria Role 错误。我知道我可以使用 !-- svelte-ignore a11y-no-static-element-interactions --> 但这仅适用于一个组件页面。 如何禁用终端中弹出的所有错误?我不同意,总的来说我只是不想遵守“规则”。 我需要在 vite.config.js 或 svelte.config.js 中进行更改吗?

accessibility sveltekit
1个回答
0
投票

根据 vite-plugin-svelte 文档,您可以在 svelte.config.js 中使用 onwarn 标志:

export default defineConfig({
  plugins: [
    svelte({
      onwarn(warning, defaultHandler) {
        // don't warn on <marquee> elements, cos they're cool
        if (warning.code === 'a11y-distracting-elements') return;

        // handle all other warnings normally
        defaultHandler(warning);
      }
    })
  ]
});

这是文档中的示例,显然您需要更新警告:

export default defineConfig({
  plugins: [
    svelte({
      onwarn(warning, defaultHandler) {
        if (warning.code === 'a11y-no-static-element-interactions') return;

        // handle all other warnings normally
        defaultHandler(warning);
      }
    })
  ]
});
© www.soinside.com 2019 - 2024. All rights reserved.