svelte-add icon indicating copy to clipboard operation
svelte-add copied to clipboard

ESM PostCSS configs option

Open nosovk opened this issue 2 years ago • 11 comments

postcss-load-config now supports esm configs. https://github.com/postcss/postcss-load-config/pull/234

After accepting of https://github.com/sveltejs/svelte-preprocess/pull/520/ we can update generated config to .js instead of .cjs

nosovk avatar May 27 '22 08:05 nosovk

This is great news! Thank you for the heads up — I wouldn't have heard about this without it!

babichjacob avatar May 28 '22 06:05 babichjacob

Bumping this up.

oneezy avatar Jun 10 '22 21:06 oneezy

correct me if i'm wrong, but this will allow using ESM for Tailwind config now too? so both tailwind.config.js and postcss.config.js will be JavaScript files and not CommonJS ?

oneezy avatar Jun 13 '22 00:06 oneezy

It turns out that Vite itself has to be updated to support ESM PostCSS configs (because it doesn't use postcss-load-config) before we can use them in our projects. 😞

babichjacob avatar Jun 15 '22 20:06 babichjacob

correct me if i'm wrong, but this will allow using ESM for Tailwind config now too? so both tailwind.config.js and postcss.config.js will be JavaScript files and not CommonJS ?

We have to wait for Tailwind themselves to update both their library (PostCSS plugin) and IntelliSense extension to support ESM configs; we're not getting it for free with PostCSS supporting ESM configs, unfortunately.

babichjacob avatar Jun 15 '22 20:06 babichjacob

We have to wait for Tailwind themselves to update both their library (PostCSS plugin) and IntelliSense extension to support ESM configs; we're not getting it for free with PostCSS supporting ESM configs, unfortunately.

Ah man that sucks! hopefully they get out some updates soon. I'm hoping there's some open issues on their ends.

oneezy avatar Jun 17 '22 01:06 oneezy

I forgot we can import PostCSS config and give it to Vite without using their loader, so this is a note to self to try that.

babichjacob avatar Jun 25 '22 22:06 babichjacob

The answer is yes! Since this is a little weird, I'll implement it as an option.

babichjacob avatar Jun 30 '22 00:06 babichjacob

I just wanted to chime in. From what little I understand, it's not just that a svelte-add issue, is it?

When I have a tailwind.config.js (note the extension: it's js not cjs) and in the package.json type is set to module, apparently vite doesn't know how to handle the tailwind configuration. I do need the tailwind configuration though, to build a method, that discovers the current breakpoint being used in order to either deliver e.g. long names (of e.g. months) or short ones.

Or is there a way to do it? Is this even the correct place to ask or should I go to Stackoverflow and pray someone with the actual knowledge responds?

divStar avatar Aug 21 '22 20:08 divStar

You're right, Tailwind itself must be updated to support ESM configs. We are however able to write the PostCSS config in ESM, wherein the Tailwind plugin will still use the tailwind.config.cjs file

babichjacob avatar Aug 22 '22 05:08 babichjacob

Now that Tailwind CSS supports ESM, we can push this forward!

https://tailwindcss.com/blog/tailwindcss-v3-3#esm-and-typescript-support

oekazuma avatar Mar 29 '23 07:03 oekazuma