Using postcss with plugin postcss-nesting in svelte is quite easy -- adding postcss-nesting
to the preprocess
config in svelte.config.js is the only thing needed:
import preprocess from "svelte-preprocess";
import postcssNesting from "postcss-nesting";
const config = {
preprocess: preprocess({
postcss: {
plugins: [
postcssNesting()
]
}
}),
// ...
};
export default config;
Now I can define nested CSS using the "&" syntax.
For example, when I have this in an example.svelte file:
<div class="example">
One <span class="nested">two</span> three
</div>
<style lang="postcss">
.example {
color: red;
& .nested {
text-decoration: underline;
}
}
</style>
However, I was not able to find a way that eslint does accept it. It reports that an identifier is expected after the & character.