css-loader localIdentName: is a hash necessary for uniqueness?

Scotty H picture Scotty H · Feb 20, 2018 · Viewed 9.6k times · Source

The css-loader README suggests that localIdentName be set to

'[path][name]__[local]--[hash:base64:5]'

Is the hashing suffix necessary? Would it still be unique as this?

'[path][name]__[local]'

Why or why not?

The fact that #3 is an option in this GitHub Issue discussion leads me to believe it may not be necessary.

Answer

jordiburgos picture jordiburgos · Feb 23, 2018

The localIdentName is used along with the modules options:

{
  loader: 'css-loader',
  options: {
    modules: true,
    localIdentName: '[path][name]__[local]--[hash:base64:5]'
  }
}

It generates longer class names like:

.src-styles-main__world-grid--R7u-K
 ---------------  ----------  -----
      path,name     local      hash

.src-styles-main__world-grid
 ---------------  ----------
      path,name     local

So, the hash would not be needed as long as path, name and class name generate unique IDs. It is very unlikely that the hash would be needed.