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

Doesn't work with latest styled-jsx #8

Open
Yuripetusko opened this issue May 24, 2017 · 10 comments
Open

Doesn't work with latest styled-jsx #8

Yuripetusko opened this issue May 24, 2017 · 10 comments

Comments

@Yuripetusko
Copy link

Hi,

It doesn't seems to work with latest code in styled-jsx master branch which allows for external files

vercel/styled-jsx@02e203f

i guess they probably do some kind of babel transpiling of files on the fly of their own? this is kind of string I get when trying to import file with latest styled-jsx:
screenshot 2017-05-24 01 07 38

@davibe
Copy link
Owner

davibe commented May 25, 2017

Unfortunately I am not working on this kind of stuff (web) anymore so i am afraid i won't be able to help much, at least not until I will be back on a web project. Sorry

@tgoldenberg
Copy link

Really too bad, since I was loving using scss with Next.js. Since the security update, I have to upgrade 2.4.1, and can't figure out how to fix the scss loading. Hope that someone is able to come along and adapt the solution.

@tgoldenberg
Copy link

Logged my fix here @Yuripetusko

@tgoldenberg
Copy link

Actually, getting the same error again. Unsure what the issue is.

@tgoldenberg
Copy link

@Yuripetusko, have you found any solution?

@Yuripetusko
Copy link
Author

@tgoldenberg yes we did, not sure what exactly helped us exactly. This is content of next.config.js

config.module.rules.push(
      {
        test: /\.(css|styl)/,
        loader: 'emit-file-loader',
        options: {
          name: 'dist/[path][name].[ext]',
        },
      },
      {
        test: /\.css$/,
        use: [
          'babel-loader',
          'raw-loader',
        ],
      },
      {
        test: /\.styl$/,
        use: [
          'babel-loader',
          'raw-loader',
          {
            loader: 'stylus-loader',
            options: {
              sourceMap: false,
              includePaths: ['styles', 'node_modules', 'components']
                .map(d => path.join(__dirname, d))
                .map(g => glob.sync(g))
                .reduce((a, c) => a.concat(c), []),
            },
          },
        ],
      }
    );

This is content of babelrc:

"presets": ["next/babel"],
      "plugins": [
        "inline-react-svg",
        [
          "transform-define",
          "./scripts/env-config.js",
        ],
        [
          "module-resolver", {
            "root": ["."],
            "alias": {
              "styles": "./styles",
              "components": "./components",
              "generic": "./components/generic",
              "svg": "./components/svg",
              "lib": "./lib"
            },
            "cwd": "babelrc"
        }],
        [
          "wrap-in-js",
          {
            "extensions": ["css$", "styl$"]
          }
        ]
      ]

And here's postcss.config.js

module.exports = {
  plugins: [
    require('postcss-easy-import')({ prefix: '_' }), // keep this first
    require('postcss-cssnext')(
      {
        /* ...options */
      }
    ),
    require('cssnano')({
      preset: 'default',
    }),
  ],
};

And we import files like so:

import ComponentStyles from './checklist-tool-header.styl';
<style jsx>{ComponentStyles}</style>

or sometimes

<style jsx global>{ComponentStyles}</style>

@Yuripetusko
Copy link
Author

"next": "3.0.0-beta10",

@tgoldenberg
Copy link

@Yuripetusko were you able to get postcss-loader to work as well? Seems that your setup works except with postcss-loader

@dvakatsiienko
Copy link

Hello, guys! @Yuripetusko @tgoldenberg noticed that you came up with a solution how to make work next.js with scss in a good way! Your solution looks really awesome! this is exactly what I'm trying to setup. I see some configs commented by @Yuripetusko but they include some files that are not highlighted here, like ./scripts/env-config.js, in .babelrc for example. Could you please share a basic full example how to make this work?

@ilionic
Copy link

ilionic commented Jul 16, 2017

@dvakatsiienko env-config not related to styles setup so you could ignore it. ( just defining some app config globals)

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