Css-loader: Webpack 2 localIdentName [folder] is empty

Created on 2 Nov 2016  路  5Comments  路  Source: webpack-contrib/css-loader

Here is part of config

{
    test: /\.(scss|sass|css)$/,
    use: [
      'style-loader',
      {
        loader: 'css-loader',
        options: {
          localIdentName: '[folder]_[path]__[name]_[local]__[hash:base64:16]',
          modules: 1,
          importLoaders: 1
        }
      },
      {
        loader: 'postcss-loader'
      }
    ]
  }
structure of project is 
components
 MyComponent
   index.js
   style.js

I need in [folder] tag to avoid same classes names in different css/sass files

P.S.
Why we can't do something like this in getLocalIdent file:

...
options.content = options.hashPrefix + request + "+" + loaderContext.resourcePath + '#' + localName;
...

Most helpful comment

Also, @MikeLP if you are using LoaderOptionsPlugin ensure you have context.
My code with LoaderOptionsPlugin and correct localIdentName:

    new webpack.LoaderOptionsPlugin({
      options: {
        context: __dirname,
        postcss: [
          // bunch of plugins
        ],
      },
    }),

All 5 comments

Are you using LoaderOptionsPlugin? Try disable LoaderOptionsPlugin and see if [folder] is still empty.

I believe this is related to #340

Hi rnons, I had the same problem, before I disabled LoaderOptionsPlugin, with the localIdentName, thanks!

Also, @MikeLP if you are using LoaderOptionsPlugin ensure you have context.
My code with LoaderOptionsPlugin and correct localIdentName:

    new webpack.LoaderOptionsPlugin({
      options: {
        context: __dirname,
        postcss: [
          // bunch of plugins
        ],
      },
    }),

@keske OMG CONTEXT IN OPTIONS!!!! THANK YOU

@keske Thanks.

Was this page helpful?
0 / 5 - 0 ratings