Skip to content

CSS Modules Naming #157

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
joezimjs opened this issue Oct 2, 2015 · 8 comments
Closed

CSS Modules Naming #157

joezimjs opened this issue Oct 2, 2015 · 8 comments

Comments

@joezimjs
Copy link

joezimjs commented Oct 2, 2015

CSS Loader creates its class names simply with some sort of hash.

The CSS Modules spec actually uses .folder_file_className_h45H or something similar when attempting to make unique class names. This is preferable since it is now easier to determine what the class is and where it comes from instead of guessing or following an odd rabbit trail to figure it out.

Are there plans to start using the CSS Modules spec for this, or at least give us the option to use it? Can there be?

@joezimjs
Copy link
Author

joezimjs commented Oct 2, 2015

Nevermind... somehow missed localIdentname all this time. Is there a way to make the [path] portion relative to a certain url so I don't have super long paths in the class name?

@joezimjs
Copy link
Author

joezimjs commented Oct 9, 2015

ping...
I'm hoping to be able to adjust what [path] outputs. Right now it's 4 folders deep when I only want one: src-client-styles-components instead of being based in the styles path and outputting just components.

@sokra
Copy link
Member

sokra commented Oct 19, 2015

you can pass context as query param. pass an absolute path to the root for the naming.

@joezimjs
Copy link
Author

Doesn't seem to be working, and I don't see any mention of context in the documentation...

@sokra
Copy link
Member

sokra commented Oct 21, 2015

yep, you're right. Sorry. It's missing here: https://github.com/webpack/css-loader/blob/master/lib/processCss.js#L152

@joezimjs
Copy link
Author

So is it not implemented? I'm not familiar with what that code is doing so I'm not sure what you're showing me. If it isn't implemented, can you implement it? Otherwise, can you give me an example how you can configure it to use the context?

@sokra sokra closed this as completed in 55ad466 Oct 21, 2015
@joezimjs
Copy link
Author

I actually read through the code more and figured out how to do it without the query:

{
    module: {
        loaders: [...]
    },
    output: {...},
    plugins: [...],
    devtool: 'source-map',
    context: ABS_PATH // <- Add it here
}

This then applies to everything, not just the CSS, but that shouldn't be an issue. It's nice to have the option that you now added, though. Thanks.

@sokra
Copy link
Member

sokra commented Oct 21, 2015

css-loader?localIdentName=[path][name]--[local]&context=/abs/path/to/directory

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

2 participants