我的图形设计师格式化我们的Svelte应用程序的方法是在LESS中有一组系统的类,在组件或页面中导入适当的LESS文件,然后在需要的地方应用这些类。因此,我们有大量的未使用的类,我们可能会在以后使用。
关于Svelte的伟大之处在于,未使用的CSS不会被编译,所以所有那些(尚未)冗余的类都不会碍事。然而,每当我们编译时,我们都会得到一个很大的警告列表:未使用的CSS选择器。这是一个很大的麻烦,因为它使得在创建实际错误时更难注意到。而且看起来很丑
我检查了文档,有一种方法可以抑制警告,但这只适用于HTML部分。
有没有办法消除这些警告?请注意,我们使用Svelte Preprocess。
5条答案
按热度按时间dldeef671#
我发现这个解决方案有点平滑,我稍微修改了一下:
pxyaymoc2#
似乎没有任何可能以适当的方式关闭此警告。但是,有一个变通办法。
在 node_modules/svelte/compiler.js 中,删除第24842行或将其放入注解中:
this.stylesheet.warn_on_unused_selectors(this);
当您更新或重新安装svelte时,您将不得不再次执行此操作。
11dmarpk3#
你必须让编译器不呕吐,也让VSCode不对你大喊大叫。
工作区级VSCode设置
sveltekit.config.ts
https://github.com/sveltejs/language-tools/issues/650#issuecomment-1729917996
ajsxfq5m4#
我使用一个简单的
explicit
忽略机制:首先,定义warning键和正则表达式来捕获ignore消息的内容。然后,循环遍历
ignore patterns
并匹配至少一个。显式比隐式更好!
9avjhtql5#
无需创建
rollup.config.js
文件,只需配置vite.config.js
即可: