对所有文件应用 svelte-ignore 警告注释

Apply svelte-ignore warning comment to all files

我的控制台收到一堆警告,说 "Unused CSS selector" 来自其他文件的 css 或 css 已被删除。它可能与 https://github.com/sveltejs/sapper/issues/842 有关,但现在我只是在寻找一种方法来防止未使用的 css 选择器警告出现在控制台中。

我曾尝试在 _layout.svelte 和 template.html 文件的顶部写注释,如下所示:<!-- svelte-ignore css-unused-selector --> 就像这里所做的那样:https://svelte.dev/docs#Comments,但它没有工作。我可以通过并将其添加到每个文件,但我想知道是否有办法使其适用于所有文件。谢谢

我在导入第三方 scss 库时 运行 遇到了这个问题。一种选择是在 rollup.config.js 文件中删除此警告。这涉及创建自定义 onwarn 处理程序。像这样:

export default {
    client: {
        ...
            svelte({
                dev,
                hydratable: true,
                emitCss: true,
                preprocess,
                // Warnings are normally passed straight to Rollup. You can
                // optionally handle them here, for example to squelch
                // warnings with a particular code
                onwarn: (warning, handler) => {
                    // e.g. don't warn on <marquee> elements, cos they're cool
                    if (warning.code === 'PLUGIN_WARNING') return;

                    // let Rollup handle all other warnings normally
                    handler(warning);
                }
            }),
            ...
    },
    ...
}

上面的配置只是一起抛出了 css-unsed-selector 警告。在此处的文档中找到完整的详细信息:https://github.com/sveltejs/rollup-plugin-svelte#usage