nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
53.34k stars 4.88k forks source link

extractCSS problem #2588

Closed do-web closed 5 years ago

do-web commented 6 years ago

extractCSS: true, merge all css in a single css file app.css, so styles for other pages gets overwritten, please create a css file for each page.

This question is available on Nuxt.js community (#c2253)
cesasol commented 6 years ago

scoped styles

binggg commented 6 years ago

@cesasol

Scoped style only works for element that in component.

For example, each page defines body background, styles will overwritten by the last page's css.

hankanon commented 6 years ago

I also encountered the same problem,Need some help and advice

cesasol commented 6 years ago

The way I managed to solve this is with dynamic page classes <nuxt :class="['layout__page', 'layout__page-' + $route.name]"/></nuxt>


.layout {
  ...
  &__page {
    &-index {
      background-color: red;
    }
   &-second {
      background-color: blue;
    }
  }
}

and this example corresponds to two vue files named index and demo inside the pages folders, you can also use a computed propety to transform the path or the params into a css string.

If your case is even more complex you can also use a meta middleware and combine everything, name of the route, params for the route and meta of the page wich can come from an api or user input
husayt commented 6 years ago

Seems this will be resolved with next release by the virtue of changes which @pi0 is doing

pi0 commented 6 years ago

@husayt Actually not only me but the entire team, @clarkdo, and @Atinux are working on fixes :)

husayt commented 6 years ago

I actually was referring to changes around extractcss I saw you made, but yes, kudos to the whole team. I have seen the waterfall of changes coming in. Seems it's going to be the largest release since 1.0.0. All the best, guys, can't wait for that

setLylToxlx commented 6 years ago

@do-web
I have the same problem Did you solve this ?

manniL commented 5 years ago

In nuxt-edge you can use optimization from webpack4 to set up your split behaviour (together with extractCss). By default, the CSS isn't merged in one file anymore.

If this behavior is still wanted, see #3166 for a solution

ghost commented 5 years ago

This bug-report has been fixed by @manniL.

Default behavior when using extractCSS in nuxt-edge

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.