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

Sass styles are not loaded when nuxt-windicss is enabled #173

Open
abhay-agarwal opened this issue May 1, 2022 · 9 comments
Open

Sass styles are not loaded when nuxt-windicss is enabled #173

abhay-agarwal opened this issue May 1, 2022 · 9 comments

Comments

@abhay-agarwal
Copy link

abhay-agarwal commented May 1, 2022

If I enable the nuxt-windicss plugin, my sass styles as defined in the nuxt config css parameter are not loaded. This does not happen if I use a css stylesheet.

import { defineNuxtConfig } from 'nuxt'

export default defineNuxtConfig({
    modules: ['nuxt-windicss'],
    css: ['~/assets/css/test.sass'],
})
{
  "private": true,
  "scripts": {
    "dev": "nuxi dev",
    "build": "nuxi build",
    "preview": "nuxi preview",
    "start": "node .output/server/index.mjs"
  },
  "engines": {
    "node": "16.x"
  },
  "devDependencies": {
    "nuxt": "3.0.0-rc.1",
    "nuxt-windicss": "latest",
    "sass": "latest",
    "sass-loader": "latest",
  },
}
@skizer
Copy link

skizer commented Jun 1, 2022

bump - still happens for me

@harlan-zw
Copy link
Member

harlan-zw commented Jun 1, 2022

Hey @abhay-agarwal & @skizer

Are you able to provide a reproduction in stackblitz?

I've attempted to replicate the issue and haven't been able to here: https://stackblitz.com/edit/nuxt-3-windicss-ohqssr?file=windi.config.ts

@skizer
Copy link

skizer commented Jun 1, 2022

Hey @harlan-zw, thanks for that fast response,
I gotta correct myself, sass itself and on its own is working - sorry!

What specifically is not working and what I was doing is using @apply in a nuxt sfc inside a style tag set to sass lang.

<style lang="sass">
#test
  @apply bg-red-600
</style>

Seems like a nuxt-windicss problem as the vite plugin works flawlessly in that way?

@abhay-agarwal
Copy link
Author

Hey @abhay-agarwal & @skizer

Are you able to provide a reproduction in stackblitz?

I've attempted to replicate the issue and haven't been able to here: https://stackblitz.com/edit/nuxt-3-windicss-ohqssr?file=windi.config.ts

I have tried again with the most recent nuxt-windicss and the problem persists. The plugin works in yarn dev mode, but once you yarn build && yarn start the styles are not visible anymore.

@abhay-agarwal
Copy link
Author

I should also mention that the latest version I found without this issue is 2.2.8, so it only occurs when I use a later version than that.

@harlan-zw
Copy link
Member

harlan-zw commented Jul 11, 2022

Hey guys, apologised for the delay in the response. Took the last month off travelling,

I've been able to replicate the issue. The issue is related to how the Vite plugin handles the order in which to transform CSS.

By default, the Vite plugin transforms CSS after it's been loaded by any pre-processors (sass, less, postcss, etc). This is okay but it means a lot of the styles in the Vue SFC don't work.

To get around this the Nuxt module sets the default transform CSS to happen before the pre-processors transformCSS: 'pre'. This allows users to use @apply in the most common css langs.

You can likely get the @apply working by setting the following, though you may run into other issues.

  windicss: {
    transformCSS: 'post'
  },

The webpack plugin gets around this using pitching to determine the best time to process the styles. This most likely won't get ported to the vite plugin as it's mostly in a maintenance phase at the moment.

Your options would be:

  • use scss
  • try UnoCSS
  • try the above transformCSS and see if it solves it

@huangxg
Copy link

huangxg commented Feb 13, 2023

sass and scss don't work for me. I have to downgrade to 2.2.8.

@volk234
Copy link

volk234 commented Mar 21, 2023

SCSS function @each doesn't work when nuxt-windi enabled. This code does nothing;

$sizes: 40px, 50px, 80px;

@each $size in $sizes {
    .icon-#{$size} {
        font-size: #{$size};
        height: #{$size};
        width: #{$size};
    }
}

When windi disabled, it works fine.

@huangxg
Copy link

huangxg commented May 31, 2023

2.2.11 is fine, but sass is not loaded with 2.3.0. It seems that some change in this commit is the cause.

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

5 participants