Next.js: How to implement SCSS in _document.js for global styling?

Created on 4 Oct 2018  路  5Comments  路  Source: vercel/next.js

Question about Next.js

I have have a file "style.scss" and I want to import it to _doucment.js file to add it to the Header there and use it across all pages , I am using
import "./syles.css

this approch works in the components very well , but it is not working in _document.js . I have read some solutions for issues related to this,and I tried but it didn't work ,I think the answer is simple but I am still able to figure out how ? ! thanks in advance for help

Most helpful comment

@jbsmith731 , it works , thank you very much , now I can go party :D

All 5 comments

any information please?

@JSMindBlowing I put my global styles in a custom _app.js

https://github.com/zeit/next.js#custom-app

@jbsmith731 thanks for replying.. can you provide the way how you implement it please?

@JSMindBlowing This is a simplified version of what I do. I use css modules so that's where import s from 'style.scss' & s.Layout comes from.

import React from 'react'
import App, { Container } from 'next/app'
import s from 'style.scss'

export default class MyApp extends App {
  static async getInitialProps({ Component, router, ctx }) {
    let pageProps = {}

    if (Component.getInitialProps) {
      pageProps = await Component.getInitialProps(ctx)
    }

    return { pageProps }
  }

  render () {
    const { Component, pageProps } = this.props

    return (
      <Container>
       <div className={s.Layout}>
          <Component {...pageProps} />
       </div>
      </Container>
    )
  }
}

@jbsmith731 , it works , thank you very much , now I can go party :D

Was this page helpful?
0 / 5 - 0 ratings