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 can I have a separate CSS or SASS folder? #3025

Closed
Itagiba opened this issue Oct 1, 2017 · 6 comments
Closed

How can I have a separate CSS or SASS folder? #3025

Itagiba opened this issue Oct 1, 2017 · 6 comments

Comments

@Itagiba
Copy link

Itagiba commented Oct 1, 2017

I am using your CSS example to add postcss to my project but unless I put my css inside the ./pages folder I get an undefined error.

import {stylesheet, classNames} from 'css/styles.css'

I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

For the paragraph class from styles to render.

.paragraph { composes: font-color from 'global.css'; font-size: 20px; color:red; }

Current Behavior

ERROR  Failed to compile with 1 errors    

This dependency was not found:

* css/styles.css in ./pages?entry

To install it, you can run: npm install --save css/styles.css

My next.config.js file is as follows:

const fs = require('fs')
const trash = require('trash')

module.exports = {
  webpack: (config) => {
    config.plugins = config.plugins.filter(
      (plugin) => (plugin.constructor.name !== 'UglifyJsPlugin')
    )

    config.module.rules.push(
      {
        test: /\.css$/,
        use: [
          {
            loader: 'emit-file-loader',
            options: {
              name: 'dist/[path][name].[ext]'
            }
          },
          {
            loader: 'skeleton-loader',
            options: {
              procedure: function (content) {
                const fileName = `${this._module.userRequest}.json`
                const classNames = fs.readFileSync(fileName, 'utf8')

                trash(fileName)

                return ['module.exports = {',
                  `classNames: ${classNames},`,
                  `stylesheet: \`${content}\``,
                  '}'
                ].join('')
              }
            }
          },
          'postcss-loader'
        ]
      }
    )

    return config
  }
}

The only time this works is if I add all the CSS files inside the ./pages directory which I find will become messy and bloated. I am using React.js with Next.js. I presume the same problems will arise if I add an ./assets folder at the same level as ./pages. How can I keep the file types separated and/or for <style dangerouslySetInnerHTML={{__html: stylesheet}} /> to render an external stylesheet instead of styles?

@timneutkens
Copy link
Member

Are you using any of the predefined examples on how to use imported styling?
https://github.com/zeit/next.js#faq

How do I use CSS preprocessors like SASS / SCSS / LESS?

@Itagiba
Copy link
Author

Itagiba commented Oct 1, 2017

Yes, this one: https://github.com/zeit/next.js/tree/master/examples/with-scoped-stylesheets-and-postcss. As per above. For some reason I cannot place the stylesheets in a folder outside of ./pages

@timneutkens
Copy link
Member

cc @thomaslindstrom

@thomaslindstrom
Copy link
Contributor

thomaslindstrom commented Oct 8, 2017

I just tried this myself and there seems to be an issue with your configuration.

screen shot 2017-10-08 at 19 52 17

This worked as expected.

@timneutkens
Copy link
Member

Okay great, thanks for checking @thomaslindstrom ❤️

@lock
Copy link

lock bot commented May 10, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018
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

3 participants