Skip to content

How to control the generation of the [path] value in the context of localIdentName? #328

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

Closed
gajus opened this issue Sep 6, 2016 · 3 comments

Comments

@gajus
Copy link

gajus commented Sep 6, 2016

I have a loader configured as:

{
  loader: 'css',
  query: {
    'modules': 1,
    'importLoaders': 1,
    'localIdentName': '[path]___[name]___[local]'
  }
},

Which generates path as:

_-app-containers-BlogContainer-___styles___live-blog

The "_-" at the beginning and "-" at the end of the [path] value are undesirable.

Is there a way to control the generation of this variable?

This is causing compatibility issues with https://github.com/css-modules/css-modules-require-hook

@gajus
Copy link
Author

gajus commented Sep 6, 2016

I had a quick look at the source code.

getLocalIdent is using require('loader-utils').interpolateName to interpolate the class name.

The [path] value is extracted from options.context (which is referring to your webpack config) and a relative path is generated to the loaderContext.resourcePath (which is referring to the path of the resource being loaded).

There appears to be no way to overwrite this logic.

@sokra it would be nice to have a callback like the one provided by postcss-modules, generateScopedName.

p.s. In my particular case, the _- suffix turned out to be an indication of an unexpected options.context path.

@timse
Copy link

timse commented Jan 21, 2017

wouldnt getLocalIdent help here? to just generate your own name?

@michael-ciniawsky
Copy link
Member

@gajus Could you try @timse suggestion ? Otherwise has you already stated, this is likely to be a a won't fix 😛. Please feel free to reopen if there is a way I'm missing out

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

3 participants