Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 206
Scotty H Avatar asked Feb 20 '18 16:02

Scotty H


2 Answers

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.

like image 189
jordiburgos Avatar answered Nov 09 '22 07:11

jordiburgos


localidentname on webpack 4.35.3

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/i,
        loader: 'css-loader',
        options: {
          modules: {
            localIdentName: '[path][name]__[local]--[hash:base64:5]',
          },
        },
      },
    ],
  },
};
like image 28
Song Avatar answered Nov 09 '22 07:11

Song