-
-
Notifications
You must be signed in to change notification settings - Fork 432
rollup-plugin-postcss not working #699
Comments
For general support questions, you'll find https://stackoverflow.com/questions/tagged/svelte is probably a more appropriate place. You need to give a bit more context for someone to understand your use case.
|
|
To process PostCSS in Svelte To process PostCSS imported in JS files you need to use a Rollup plugin such as https://github.com/egoist/rollup-plugin-postcss. Sapper will take care of emitting the CSS assets but you do need to process it first. The order of your Rollup plugins can also be important. |
@maxmilton As far as i'm aware, Svelte outputs the CSS file(s) to rollup, for rollup-plugin-postcss to take care of. This works fine with svelte by itself, but not with sapper! |
Svelte first parses the If you want your If it's just the CSS files imported in JS that you're having issues with I suggest looking over your rollup PostCSS plugins docs. |
I made a repo to demonstrate my issue. https://github.com/JoelEllis/sapper-postcss-issue Quick side note - sapper seems to not work in Git Bash - if you run it in a fresh repo, it give some kind of error about can't find undefined\client.js. Possibly to do with git bash making windows paths POSIX so \ is an escape character rather than the path seperator in git bash? |
I run into this issues as well. Adding these to svelte rollup config fix it for me:
|
@dephiros That works great. Thanks. |
In some of my projects it doesn't work though. I'm working around that by removing psotcss form the build, getting sapper to output css seperately and running |
@JoelEllis This is based on the official template https://github.com/nhristov/sapper-template-rollup. It adds postcss, purgecss, cssnano, tailwindcss and svelte-preprocess without having to modify the build script in your package.json |
Just reposting here what I replied to @nhristov's email with: It seems to work great Just to note now, I'm not really in the same environment as I was when I made that issue - I used to be on windows (10 home), I've moved to a Linux system full-time now. |
After some testing, I figured out how the repo works, and it seems a bit weird to have a ganerated & minifed style comitted to git? |
Dispite this solving my problem, I don't think this really solves the bug (or incompatibility). It's a workaround, in my opinion. The issue is what causes the incompatibility with postcss, and how do we fix it without requiring a non-obvious workaround. This could be a bug in rollup, but I've only seen it occur with sapper. If this is going to be a |
@JoelEllis I'm struggling to determine from this reading issue, because it's not clear:
Regarding the third point - from what I can ascertain, your problem stems from using postCSS in Sapper. Sapper doesn't natively support PostCSS, so we wouldn't necessarily document a solution for PostCSS in the main Sapper docs. If this is a problem with Rollup then we can raise the issue / fix the issue there. Also I notice your reproduction is archived. Do you have a new, simplified reproduction so that we can see the issue for ourselves? Thanks! |
Hey! The work around I'm using/have been given is https://github.com/nhristov/sapper-template-rollup - use PostCSS as a preprocessor for css inline in svelte, use PostCSS's rollup plugin to minify external CSS files (imported in server.js). This isn't ideal as CSS imported in client.js is not processed and the CSS from sapper is not processed as a whole, meaning minifers can't work at their full potential and there are newlines left in the files. However, it's good enough. My ideal solution is to make situations 1 & 2 output valid CSS, or to document the workaround, @nhristov told me to document their workaround by making a question/answer on stackoverflow. |
I can't determine that there is an actual issue with Sapper from this ticket, so closing. Feel free to re-open if you can isolate/point at an exact issue with Sapper itself. |
@antony I think I know why this bug occurs.
Therefore, postcss plugin emits files after we collect files for bundle. It seems also, that emitting file during Note, that this is probably this is only the part of the problem. |
Thanks for the excellent investigation @krzysztof-grzybek! |
Is there a workaround for now? Because I'd really like to be able to use this soon. |
I used @dephiros workaround. |
That doesn't work for me. I did find out how to fix the bug mostly. I'm gonna submit a very bad PR in a few minutes, hoping that other people are willing to improve it so that it can be merged. |
There's a template that @babichjacob has provided at https://github.com/babichjacob/sapper-postcss-template. As far as I know, he hasn't hit this issue (feel free to correct me @babichjacob). Would using his setup work for you all? I'd be curious to know if it has some issue or if it only happens when some other setting is present |
It's been a while since I tried it, but IIRC the problem appears when using |
We don't have this issue because we don't import CSS-like files in JS. We also don't use
<style lang="postcss"> <!-- possibly with global -->
@import "./styles.css";
</style> with |
Ah yes I see that it does work if I import the css in a |
Oh no, I said this off of memory and was wrong. We actually do have |
Ah, so this bug seems to me to really be specific to |
@krzysztof-grzybek nice work!! |
Just in case here a reference using Sapper with PostCSS fixed -> https://dev.to/csaltos/sapper-with-material-ui-35id (it uses SMUI as a bonus) |
Thanks @csaltos |
I would recommend using the |
What exactly does that look like for those of us struggling with this that aren't familiar with bundler configurations.
CC: @benmccann |
I would recommend switching to SvelteKit. Then you can simply run |
I can't seem to get postcss to work properly and extract my css like it does in pure svelte.
With css extract option on it generates:
but with it off, it generates:
In normal svelte when I do
import './global.css'
, it generates a inlined bit of js with it off, and the processed file with it on, and does the same for svelte's generated CSS.I can't figure out what's going wrong, but I would like my css minified and prefixed.
The text was updated successfully, but these errors were encountered: