question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getLocalIdent option from css-loader doesn't work

See original GitHub issue

In my webpack.config I have following setup:

function genStyleLoaders(_opts) {
  const opts = Object.assign({}, {
    styleLoader: 'style-loader',
    scss: false,
    cssModules: false,
  }, _opts || {});

  let loaders = [
    opts.styleLoader,
    {
      loader: 'css-loader',
      options: Object.assign({}, {
        minimize: env.__PROD__,
        importLoaders: 1,
        sourceMap: DEV,
        modules: opts.cssModules,
        getLocalIdent: (context, localIdentName, localName, options) => {
          return 'whatever_random_class_name';
        },
      }, CSS_MODULES_OPTS),
    },
    'postcss-loader',
  ];

  if (opts.scss) {
    loaders = loaders.concat({
      loader: 'sass-loader',
      options: Object.assign({}, plugins.sass, {
        sourceMap: DEV,
        sourceMapContents: DEV,
      }),
    });
  }

  return loaders;
}

// vue-loader rule
{
  test: /\.vue$/,
  loader: 'vue-loader',
  include: paths.appSrc,
  options: {
    loaders: {
      css: genStyleLoaders({
        styleLoader: 'vue-style-loader',
      }),
      scss: genStyleLoaders({
        styleLoader: 'vue-style-loader',
        scss: true,
      }),
    },
    cssModules: CSS_MODULES_OPTS,
  },
}

and basically when i import my styles through <style> block in .vue component

<style src="./Auth.scss" lang="scss" module></style>

all css classes starts with Auth prefix (Auth__card___3Q2YJ) when they should start with whatever_random_class_name. It works fine when I import styles in script tag:

import style from './Auth.scss';

export default {
  created() {
    this.$style = style;
  }
}

If i am not mistaken I think vue-loader simply doesn’t support this option right now? Would be great if vue-loader would support this option as well. Thanks 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
yyx990803commented, Apr 6, 2017

This is because vue-loader loaders have to be stringified so the function option is dropped in the process. We will need to change the loader matching strategy to solve this, but for now unforunately there’s not an easy way to work around this.

6reactions
yyx990803commented, Mar 6, 2018

Closing since this relies on some architectural re-design and currently webpack doesn’t have the ideal API for what we need.

I’ll try to work with the webpack team to see if they can make it possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modify output of localIdentName / getLocalIdent - Stack Overflow
If that doesn't work, try logging out options from getLocalIdent to see what options you have, to try to generate your preferred string....
Read more >
css-loader-getlocalident - npm
The option importLoaders allows you to configure how many loaders before css-loader should be applied to @import ed resources. webpack.config.js.
Read more >
CSS Modules with custom localIdentName / getLocalIdent
css-loader has the configuration option getLocalIdent for that. Unfortunately this does not seem to work when I set it the cssModules option.
Read more >
Diff - platform/frameworks/base - Google Git
ClassLoader ); + method public boolean allowMerge(); + method public abstract ... Options are:\n" + @@ -186,6 +193,25 @@ "am stop-user: stop execution...
Read more >
Index (vaadin-server 8.13.0 API) - javadoc.io
Constructor for setting the immutable descriptor, property set and property holder ... setDefaultClassLoader() to acquire appropriate class loader to load ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found