pugjs / babel-plugin-transform-react-pug

A plugin for transpiling pug templates to jsx
MIT License
811 stars 47 forks source link

style jsx always affects global. #100

Closed pruge closed 5 years ago

pruge commented 5 years ago

I am performing the following example. https://nextjs.org/learn/basics/styling-components/no-effect-for-nested-components

The expected state is as follows. alt image

But in reality it looks like this:

image

The example works fine. https://github.com/zeit/next-learn-demo/tree/master/7-styling-components

But if you put .babelrc here, style affects global.

{
  "plugins": [
    "transform-react-pug",
    "transform-react-jsx",
    [
      "transform-jsx-classname-components",
      {
        "objects": [
          "React"
        ]
      }
    ]
  ]
}

Is there a way to enable scope style?

ezhlobo commented 5 years ago

@pruge sorry for the delay. I'll take a closer look at examples soon and will be able to discuss the things.

ezhlobo commented 5 years ago

@pruge I see that you use Next and you try to customize babel config. According to their documentation, when you add own .babelrc file, you must include Next's stuff there (including jsx-styled).

https://nextjs.org/docs#customizing-babel-config

So in your case, simply modify your .babelrc file:

  {
+   "presets": ["next/babel"],
    "plugins": [
      "transform-react-pug",
      "transform-react-jsx",
      [
        "transform-jsx-classname-components",
        {
          "objects": [
            "React"
          ]
        }
      ]
    ]
  }

If you continue experiencing the issue, will be really helpful if you provide your repository with reproduced issue.

pruge commented 5 years ago

thank you very much