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

How to implement SCSS in _document.js for global styling? #5380

Closed
MimoJSRepo opened this issue Oct 4, 2018 · 5 comments
Closed

How to implement SCSS in _document.js for global styling? #5380

MimoJSRepo opened this issue Oct 4, 2018 · 5 comments

Comments

@MimoJSRepo
Copy link

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

@MimoJSRepo
Copy link
Author

any information please?

@jbsmith731
Copy link

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

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

@MimoJSRepo
Copy link
Author

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

@jbsmith731
Copy link

jbsmith731 commented Oct 5, 2018

@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>
    )
  }
}

@MimoJSRepo
Copy link
Author

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

@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants