Skip to content

getLocalIdent option from css-loader doesn't work #734

Closed
@sqal

Description

@sqal

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions