The svelte-language-server and therefore the VSCode extension can only handle CSS/Less/SCSS syntax. To get other syntaxes working, read on.
- Setup you build and
svelte.config.js
(general info) correctly and add apostcss.config.cjs
(note thecjs
ending; you need to write the config in CommonJS style currently, more on that below). We recommend using svelte-preprocess. For thesvelte.config.js
, this should be enough:
import sveltePreprocess from 'svelte-preprocess';
export default { preprocess: sveltePreprocess({ postcss: true }) };
Note that this assumes that you have a ESM-style project, which means there's "type": "module"
in your project's package.json
. If not, you need to use CommonJS in your svelte.config.js
, things like import ...
or export const ...
are not allowed. You then also switch the postcss.config
cjs
file ending to js
.
- Either add
lang="postcss"
to each of your<style>
tags where you plan on using PostCSS, or disable CSS diagnostics completely by adding"svelte.plugin.css.diagnostics.enable": false
within your settings. If you still want diagnostics, install the Stylelint VSCode extension. If you want better syntax highlighting, install the PostCSS VSCode extension.
We assume you already have setup TailwindCSS within your Svelte project. If not, this article and this article explain two approaches on how to do it.
To use TailwindCSS with the VSCode extension:
- Setup the
svelte.config.js
the same way you would for PostCSS - see the section above (first point) for more details - Install the Tailwind CSS VSCode extension
- Either add
lang="postcss"
to each of your<style>
tags where you plan on using the Tailwind CSS directives such as@apply
, or disable CSS diagnostics completely by adding"svelte.plugin.css.diagnostics.enable": false
within your settings. If you still want diagnostics, install the Stylelint VSCode extension and configure it accordingly. Note that within your config files you can only use node-syntax, things likeimport ...
orexport const ...
are not allowed. To disable css checks forsvelte-check
, use the option--diagnostic-sources "js,svelte"
.
- Add
lang="sass"
to your<style>
tags - If you want to have proper syntax highlighting for VS Code, install the SASS VSCode extension
- If you have problems with formatting, turn it off. If you experience wrong css diagnostic errors, turn it off
- Add
lang="stylus"
to your<style>
tags - If you want to have proper syntax highlighting for VS Code, install the language-stylus extension