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

The properties of the object returned by css modules auto transform to lowerCamelCase #8605

Closed
xyy94813 opened this issue Sep 28, 2018 · 9 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@xyy94813
Copy link

Summary

I am trying to migrate v1 to v2. In my project, i used gatsby-plugin-less, CSS Modules and React-CSS-Modules .
I found all properties of the object returned by css modules auto transform to lowerCamelCase, although i use - to split word.

Relevant information

My less file style.module.less:

:local {
    .float-card: {
        // ...
    }
}

My Component file MyComponent.js

import styles from './style.module.less'
console.log(styles); // { floatCard: "...." }

Environment (if relevant)

System:
OS: macOS High Sierra 10.13.3
CPU: x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.9.1 - /usr/local/bin/node
Yarn: 1.3.2 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Browsers:
Chrome: 69.0.3497.100
Safari: 11.0.3
npmPackages:
gatsby: ^2.0.8 => 2.0.8
gatsby-link: ^2.0.1 => 2.0.1
gatsby-plugin-antd: ^2.0.2 => 2.0.2
gatsby-plugin-import: ^2.0.1 => 2.0.1
gatsby-plugin-less: ^2.0.5 => 2.0.5
gatsby-plugin-react-helmet: ^3.0.0 => 3.0.0
npmGlobalPackages:
gatsby-cli: 2.4.2

File contents (if changed)

gatsby-config.js:

module.exports = {
  plugins: [
    'gatsby-plugin-react-helmet',
    {
      resolve: 'gatsby-plugin-less',
      options: {
        strictMath: false,
        // strictUnits: true,
        javascriptEnabled: true,
        modifyVars: {
          'primary-color': '#EA0029',
          'layout-body-background': '#FFFFFF',
          'layout-header-background': '#323232',
          'layout-footer-background': '@layout-header-background',
          'menu-dark-item-active-bg': '@layout-header-background',
        },
      },
    },
    {
      resolve: 'gatsby-plugin-import',
      options: {
        style: 'css',
      },
    },
  ],
}

package.json:

// ...

gatsby-node.js:

// none

gatsby-browser.js:

// none

gatsby-ssr.js:

// none
@xyy94813
Copy link
Author

xyy94813 commented Sep 28, 2018

How can I modify the configuration camelCase to false of css-loader

@kakadiadarpan
Copy link
Contributor

@xyy94813 can you provide a reproduction repo for this? That would make it much simpler to diagnose this issue.

@kakadiadarpan kakadiadarpan added status: needs more info Needs triaging and reproducible examples or more information to be resolved status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. labels Sep 28, 2018
@CanRau
Copy link
Contributor

CanRau commented Sep 28, 2018

@xyy94813 Have you checked out #onCreateWebpackConfig in docs?

And #376 (comment) suggests that both should be available (kebab and camel case)? Don't have a way of trying it out quickly right now, maybe it has been changed?

@kakadiadarpan
Copy link
Contributor

kakadiadarpan commented Sep 28, 2018

Thanks for providing the context @CanRau.

@xyy94813 This was mentioned in the migrating from v1 to v2 guide.

If you want to change this behavior you'll need to add custom webpack config.

You'll need make changes like below in gatsby-node.js

// gatsby-node.js
exports.onCreateWebpackConfig = ({
  stage,
  rules,
  loaders,
  plugins,
  actions,
}) => {
  actions.setWebpackConfig({
    module: {
      rules: [
        {
          test: /\.less$/,
          use: [
            loaders.css({ camelCase: false })
          ],
        },
      ],
    },
  })
}

Also in use array you'll need to add other loaders that you use like less-loader.

Let us know if you need more help. 😄

@kakadiadarpan kakadiadarpan added type: question or discussion Issue discussing or asking a question about Gatsby and removed status: needs more info Needs triaging and reproducible examples or more information to be resolved status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. labels Sep 28, 2018
@CanRau
Copy link
Contributor

CanRau commented Sep 28, 2018

@kakadiadarpan thanks for providing the code 👍 didn't had the patience to dig more into it at that time^^

@xyy94813
Copy link
Author

@kakadiadarpan thanks for your help.

it is better, if there are some way to override it in gatsby-plugin-less 😄

@kakadiadarpan
Copy link
Contributor

@xyy94813 It's not possible to override this from gatsby-plugin-less as this functionality is controlled by another loader css-loader:

camelCase: `dashesOnly`,

@CanRau
Copy link
Contributor

CanRau commented Sep 28, 2018

could you get the desired result @xyy94813? If so we could close the issue, otherwise let us know how we can support you

@xyy94813
Copy link
Author

xyy94813 commented Sep 28, 2018

@kakadiadarpan

{ postCssPlugins, ...lessOptions }

if the gatsby-plugin-less provide a option, i will become possible

exports.onCreateWebpackConfig = (
  { actions, stage, rules, plugins, loaders },
  { postCssPlugins, overrideCSSLoaderOpt, ...lessOptions }
) => {
 ....
 const lessRule = {
    test: /\.less$/,
    use: isSSR
      ? [loaders.null()]
      : [
          loaders.miniCssExtract(),
          loaders.css({ importLoaders: 2, ...overrideCSSLoaderOpt }),
          loaders.postcss({ plugins: postCssPlugins }),
          lessLoader,
        ],
  }
  // ...
}

loaders.css({ importLoaders: 2 }),

But i am not sure it is a better way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants