Luk*_*Gur 3 css sass visual-studio-code svelte sveltekit
如何删除 VS Code 未使用的 CSS 选择器警告?此警告存在于我使用的所有文件中<style lang="scss">
。我知道我不在.btn
某些组件中使用类,但我希望这个类作为全局 css。
我的svelte.config.js
:
const config = {
onwarn: (warning, handler) => {
const { code, frame } = warning;
if (code === "css-unused-selector")
return;
handler(warning);
},
preprocess: [
preprocess({
defaults: {
style: 'scss'
},
postcss: true,
scss: {
prependData: `@import 'src/scss/global.scss';`
}
})
],
};
Run Code Online (Sandbox Code Playgroud)
请问有人可以帮助我吗?
如果您使用prependData
这意味着您将导入添加到使用样式的每个组件中。这不是您想要的,因此删除此设置。您想要的是导入该文件一次,以便全局可用。只需将其导入脚本标签即可完成此操作,SvelteKit(或更确切地说:Vite)可以处理样式导入。
在你的根__layout.svelte
文件中,添加
<script>
import 'path/to/your/global.scss';
</script>
Run Code Online (Sandbox Code Playgroud)