最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why does space-y Tailwind class work on dev but not production? - Stack Overflow

programmeradmin0浏览0评论

I have built a Nuxt app using Tailwind CSS for the first time, but found that space-y-6 works fine on local but not in production - the class has no effect there.

  <div class="prose space-y-6 first-letter:font-bold first-letter:float-left first-letter:mr-3 first-letter:text-7xl">
<p>...</p>
<p>...</p>
  </div>
</template>

On local, the class in tailwind.css looks like this:

.space-y-6 {
    :where(& > :not(:last-child)) {
      --tw-space-y-reverse: 0 !important;
      margin-block-start: calc(calc(var(--spacing) * 6) * var(--tw-space-y-reverse)) !important;
      margin-block-end: calc(calc(var(--spacing) * 6) * calc(1 - var(--tw-space-y-reverse))) !important;
    }
  }

And on production it's subtly different:

.space-y-6 :where(>:not(:last-child)) {
                    --tw-space-y-reverse: 0!important;
                    margin-block-end:calc(var(--spacing)*6*(1 - var(--tw-space-y-reverse)))!important;margin-block-start: calc(var(--spacing)*6*var(--tw-space-y-reverse))!important
                }

Any ideas?

I have built a Nuxt app using Tailwind CSS for the first time, but found that space-y-6 works fine on local but not in production - the class has no effect there.

  <div class="prose space-y-6 first-letter:font-bold first-letter:float-left first-letter:mr-3 first-letter:text-7xl">
<p>...</p>
<p>...</p>
  </div>
</template>

On local, the class in tailwind.css looks like this:

.space-y-6 {
    :where(& > :not(:last-child)) {
      --tw-space-y-reverse: 0 !important;
      margin-block-start: calc(calc(var(--spacing) * 6) * var(--tw-space-y-reverse)) !important;
      margin-block-end: calc(calc(var(--spacing) * 6) * calc(1 - var(--tw-space-y-reverse))) !important;
    }
  }

And on production it's subtly different:

.space-y-6 :where(>:not(:last-child)) {
                    --tw-space-y-reverse: 0!important;
                    margin-block-end:calc(var(--spacing)*6*(1 - var(--tw-space-y-reverse)))!important;margin-block-start: calc(var(--spacing)*6*var(--tw-space-y-reverse))!important
                }

Any ideas?

Share Improve this question edited Feb 1 at 8:27 Fijjit asked Jan 31 at 19:42 FijjitFijjit 1,4872 gold badges19 silver badges33 bronze badges 3
  • 1 If space-y-6 is explicitly written in one of your files, it will definitely be included in the build. Check the generated CSS from the build to see if the class is present. If it is, and you've updated the production release, caching issues are usually the cause of such anomalies. – rozsazoltan Commented Jan 31 at 19:53
  • 1 Thanks. I've compared both local and production generated CSS and the class is in both places, but a little different on production. Something about the slightly different CSS means it's not working anymore. – Fijjit Commented Feb 1 at 8:28
  • I tested the production build with TailwindCSS v4.0.3. For me, your dev version was generated, just a optimized version of this: :where(.space-y-6 > :not(:last-child)) { ... } Are you running any additional processors when generating the build CSS that might affect the final output? Have you checked in a fresh, clean installation to see if the issue can be reproduced? – rozsazoltan Commented Feb 5 at 20:14
Add a comment  | 

1 Answer 1

Reset to default 1

By adding cssMinify to my vite build configuration and setting it to 'lightningcss' it seems to get it working again.

import tailwindcss from "@tailwindcss/vite";

export default defineNuxtConfig({
  vite: {
    plugins: [
      tailwindcss()
    ],
    build: {
      cssMinify: 'lightningcss'
    }
  },
})
发布评论

评论列表(0)

  1. 暂无评论