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

cssModules localsConvention = 'camelCase' is not reflecting in nuxt app #7223

Closed
tareq89 opened this issue Apr 15, 2020 · 4 comments
Closed

Comments

@tareq89
Copy link

tareq89 commented Apr 15, 2020

Version

v2.12.2

Reproduction link

https://codepen.io/tareq89/pen/Yzywwbe

Steps to reproduce

In the nuxt.config.js file

build: {
extend: (config, ctx) {
ctx.loaders['cssModules'].modules.localIdentName = ctx.isDev ? '[name]__[local]' : '[hash:base64:10]'
ctx.loaders['cssModules'].localsConvention = 'camelCase'
}
}

What is expected ?

In the vue component, the css class 'Banner--red' should be generated like this.$style.banerrRed = 'Banner--red'

What is actually happening?

In the vue component, the css class 'Banner--red' is being generated like this.$style.['Banner--red'] = 'Banner--red'

Additional comments?

How this problem can be solved? it looks like configuring cssModule loader from nuxt.config.js is not working.

@ghost ghost added the cmty:bug-report label Apr 15, 2020
@stale
Copy link

stale bot commented May 15, 2020

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

@stale stale bot added the stale label May 15, 2020
@stale stale bot closed this as completed May 22, 2020
@yura3d
Copy link

yura3d commented Jan 7, 2021

@tareq89 I was only able to do this by adding localsConvention directly to css-loader options:

build: {
  extend (config) {
    config.module
      .rules.find(({ test }) => test.toString() === /\.css$/i.toString())
      .oneOf.find(({ resourceQuery }) => resourceQuery && resourceQuery.toString() === /module/.toString())
      .use.find(({ loader }) => loader === 'css-loader')
      .options.localsConvention = 'camelCaseOnly'
  }
}

May be it looks some wordy, but it works.

Of course, it would be better if Nuxt provides references for loaders' options in context or in some other simplified config entity to prevent manually injection to complex webpack config. I tried doing something described in the first post (with ctx object as 2nd argument for extend()), but without any results.

@danielroe
Copy link
Member

@yura3d Something like https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-build#loaders ?

@yura3d
Copy link

yura3d commented Jan 7, 2021

@danielroe Thanks, now everything is simple and elegant:

build: {
  loaders: {
    cssModules: {
      localsConvention: 'camelCaseOnly'
    }
  }
}

Hope it will be useful for users that will come here from Google, like me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants