Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make .svelte files style tag compatible with useVitePreprocess (not only svelte-preprocess) #1479

Closed
felixsanz opened this issue May 10, 2022 · 3 comments

Comments

@felixsanz
Copy link

Description

I'm currently using useVitePreprocess and it works wonderful. It's faster because of esbuild, you can use $aliases inside style tags and everything is awesome. Unused CSS also gets removed and classes contains the scoped random symbols. In fact, it produces the same CSS as svelte-preprocess.

The issue is... the vscode extension doesn't handle <style lang="postcss"> when using useVitePreprocess. It breaks on things like nesting.

I know useVitePreprocess is experimental, but can we get this working please?

Describe the proposed solution

Proposed solution

useVitePreprocess able to work with .svelte files

Alternatives

I can use svelte-preprocess but it duplicates CSS in dev mode. Also.. why use another tool when we are already using vite?

Additional Information, eg. Screenshots

No response

@felixsanz
Copy link
Author

Just related to #1259 or 100% duplication?

dummdidumm added a commit to dummdidumm/language-tools that referenced this issue Jul 26, 2022
…lved

sveltejs#1259
sveltejs#1479
sveltejs#1558

This may give false negatives for people who do not use Vite/forgot to create a svelte.config.js when they use rollup or webpack, but that's likely OK since we can think about these diagnostics as being opt-in: you add a preprocessor config when you want the Svelte warnings, too. Most people who have this problem also likely use TypeScript or a CSS preprocessor. When using TS, errors are caught through the TS intellisense. When using a CSS preprocessor, the only warning they'll miss is the unused CSS warning, which is apparent anyway since those styles are not visible in the browser.
dummdidumm added a commit that referenced this issue Jul 27, 2022
…lved (#1569)

#1259
#1479
#1558

This may give false negatives for people who do not use Vite/forgot to create a svelte.config.js when they use rollup or webpack, but that's likely OK since we can think about these diagnostics as being opt-in: you add a preprocessor config when you want the Svelte warnings, too. Most people who have this problem also likely use TypeScript or a CSS preprocessor. When using TS, errors are caught through the TS intellisense. When using a CSS preprocessor, the only warning they'll miss is the unused CSS warning, which is apparent anyway since those styles are not visible in the browser.
@pevey
Copy link

pevey commented May 23, 2023

When following the instructions at https://tailwindcss.com/docs/guides/sveltekit, the plugin highlights an "error." I think it may be related to this issue.

The hello world test page in the instructions use this style block:

+page.svelte

<h1 class="text-3xl font-bold underline">
	Hello world!
 </h1>
 
<style lang="postcss">
	:global(html) {
	  background-color: theme(colors.gray.100);
	}
 </style>

It works fine, but the plugin show a red line under 'colors' along with this info:

"")" is expected

If you expect this syntax to work, here are some suggestions: 
If you use less/SCSS with `svelte-preprocess`, did you add `lang="scss"`/`lang="less"` to your `style` tag? If you use SCSS, it may be necessary to add the path to your NODE runtime to the setting `svelte.language-server.runtime`, or use `sass` instead of `node-sass`. 
Did you setup a `svelte.config.js`? 
See https://github.com/sveltejs/language-tools/tree/master/docs#using-with-preprocessors for more info.svelte(css-syntax-error)

The config is set up to use vitePrepocess():

svelte.config.js

import adapter from '@sveltejs/adapter-cloudflare'
import { vitePreprocess } from '@sveltejs/kit/vite'

/** @type {import('@sveltejs/kit').Config} */
const config = {
	kit: {
		// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
		// If your environment is not supported or you settled on a specific environment, switch out the adapter.
		// See https://kit.svelte.dev/docs/adapters for more information about adapters.
		adapter: adapter()
	},
	preprocess: vitePreprocess()
}

export default config

@SDAravind
Copy link

SDAravind commented Oct 29, 2023

<h1 class="text-3xl font-bold underline">
	Hello world!
</h1>

<style lang="postcss">
	:global(html) {
	  background-color: theme('colors.gray.100');
 	}
</style>

add single quote around colors.gray.100

Follow tailwindcss for sveltekit and no other cofiguration is required.

@felixsanz felixsanz closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants