-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
🐛 BUG: PostCSS example from documentation does not work (and some plugins are broken) #3528
Comments
As a Stage 1 proposal, nesting must be opted into explicitly (postcss-nesting only enables Stage 2 and later by default). So not a bug per se, but since nesting is a common-enough want, an update to the docs would probably be helpful. PR incoming! https://codesandbox.io/s/fancy-surf-h0i1wk?file=/postcss.config.js |
Ok about that, but |
Is the rendered example in that fork not working for you? https://codesandbox.io/s/fancy-surf-h0i1wk?file=/src/components/Card.astro |
Ah... that's because I was looking into the Svelte set-up: should have forked before doing that! Try this: https://codesandbox.io/s/lively-sun-9p6qyo?file=/src/components/Card.astro |
That doesn't include a .svelte component :/ |
Yes, I was trying to validate that the PostCSS integration works as described with Astro components. |
So this version uses CSS nesting in Svelte modules https://codesandbox.io/s/admiring-raman-ftigzk?file=/src/components/Card.svelte |
can you check a local project using vscode? to me crash both language-tools and the dev server |
Can you try updating import { defineConfig } from "astro/config";
import svelte from "@astrojs/svelte";
import preprocess from "svelte-preprocess";
export default defineConfig({
integrations: [
svelte({
preprocess: [
preprocess({
postcss: true,
}),
],
}),
],
}); |
Yeah i saw you importing the svelte-preprocess package in some example and i tried that already, it didn't help :( |
Can you confirm that this repo doesn't work for you? I'm running it locally without issue. |
i don't understand the magic going on! your repo works perfect. mine... after updating from b40 to b42 it doesn't crash anymore, but i can't get rid of the error that vscode shows! i reloaded astro language server, svelte language server, reloaded editor window, closed and opened a new editor 😂 |
Could this be the issue? Importing
EDIT: probably not I remember in sveltekit i had to add this to my vscode settings.json:
but it's not working here, no effect |
Just to refocus on the Astro-specific aspects, here's what I think one can say
|
Re the Svelte Language Server complaining about CSS syntax it doesn't recognise, that feels like a challenge that |
but in sveltekit this works fine! maybe astro language-tools are not reading that @Princesseuh you are in charge of language-tools right? Can you shed some light? (if you know) |
Our language tools are only running in Astro files, errors inside Svelte files are handled by the Svelte extension only. We can't show errors inside Svelte files, they can't show errors inside Astro files (Our language server does not even support CSS validation, so, we can't even show errors inside style tags in general) You shouldn't actually need that setting as the Svelte language server disable validation for style tags with lang set to PostCSS (since yeah, |
Then whose fault is it? 😆 All i can say is..
@Princesseuh I think it's needed! Comment from svelte's language tools author: sveltejs/language-tools#190 (comment) (and I can confirm that you NEED it on sveltekit or the error won't dissapear) |
@oliverturner @Princesseuh I found the issue. Astro still needs a svelte.config.js file for this to work: So Astro is missing something? astro.config.js (does NOT fix it): import { defineConfig } from "astro/config";
import svelte from "@astrojs/svelte";
import sveltePreprocess from "svelte-preprocess";
import nesting from 'postcss-nesting'
const postcssConfig = {
plugins: [
nesting,
],
}
export default defineConfig({
integrations: [
svelte({
preprocess: [
sveltePreprocess({
postcss: postcssConfig,
}),
],
}),
],
}); svelte.config.js (DOES fix it): const sveltePreprocess = require('svelte-preprocess')
const nesting = require('postcss-nesting')
const postcssConfig = {
plugins: [
nesting,
],
}
const config = {
preprocess: [
sveltePreprocess({
postcss: postcssConfig,
}),
],
}
module.exports = config |
Astro pass those settings directly to Svelte, whereas the Svelte language server expect an actual Svelte config file, I don't think there's anything we can do apart from documenting that needs (Unless the Svelte team is interested in a PR to their language tool to load our config) Thank you for finding the issue! |
So having this config inside astro.config.js is useless and does nothing? integrations: [
svelte({
preprocess: [
preprocess({
postcss: postcssConfig,
}),
],
}), or Astro still uses it to preprocess stuff in svelte components throught vite? (a.k.a.: do i need the same code twice? 😆😆) |
Yep, that config is needed for the Svelte integration to process the files, maybe we could update the integration to load a Svelte config file |
Since import svelteConfig from 'svelte.config.js'
export default defineConfig({
integrations: [
svelte(svelteConfig),
],
}); Also a change to make it work automatic sounds nice. I think if Astro still depends on other framework's language tools for this kind of things, per-framework specific config file are still needed. Thank you both for helping me debug the issue! |
@oliverturner Ah yep, it did used to autoconfigure Interesting that leaving out |
Also @oliverturner I'd love to see some beefed-up PostCSS docs there! I'll defer to your expertise but lmk if I should jump in as well. |
@felixsanz Found a fix for your Svelte issue! #3685 I noticed we weren't applying our generated PostCSS config to Svelte. This should apply all Post CSS config by default, including Tailwind defaults if you mix with that integration 👍 |
@bholmesdev how can I achieve this with latest version of astrojs/svelte? |
What version of
astro
are you using?v1.0.0-beta.40
Are you using an SSR adapter? If so, which one?
no
What package manager are you using?
npm
What operating system are you using?
Linux
Describe the Bug
https://docs.astro.build/en/guides/styling/#postcss
Documentation says that PostCSS integration can be enabled with just creating a
postcss.config.js
file, install some plugins and require them there.And it works with plugins like
autoprefixer
, butpostcss-nesting
does not work. The example in the documentation usespostcss-preset-env
(which also includespostcss-nesting
).In the test case i created i just forked the "Just the basics" repo example, installed the plugin, added
postcss.config.js
and moved the css insidecomponents/Card.astro
so it becomes:The nesting thing does not work, devtools shows an error because invalid property. In the case of doing this in a svelte component... the dev server crash and doesn't let you continue.
Looks like postcss plugins that include (at the moment) a custom syntax does not work
Link to Minimal Reproducible Example
https://codesandbox.io/s/silent-dew-fehxqz
Participation
The text was updated successfully, but these errors were encountered: