B
B
bellerofonte2022-01-17 15:35:08
JavaScript
bellerofonte, 2022-01-17 15:35:08

How to properly convert css-loader settings from string to object?

There was a file webpackfile.jswith the following content:

// .....
return {
    // ....
    module: {
        rules: [
            // ...
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader?modules&localsConvention=camelCase'
            },
            // .....
        ]
    },
    // ....
};


After updating the dependencies (webpack, react, babel, loaders, etc), webpack required to convert the string loaderinto an array use.

I converted to the following:
return {
    // ...
    module: {
        rules: [
            // ...
            {
                test: /\.css$/,
                use: [{
                    loader: 'style-loader'
                }, {
                    loader: 'css-loader',
                    options: {
                        // ???????
                    }
                }]
            },
            // .....
        ]
    },
    // ....
};


Question: what should be written in optionsinstead of ????to make it equivalent to the string modules&localsConvention=camelCase? I try different combinations, but as a result, either webpack stops building, or when the page loads, an error occurs when accessing any style class, for example (to the point):
import css from './index.css'
css.someClassName // -> Uncaught TypeError: Cannot read properties of undefined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bellerofonte, 2022-01-19
@bellerofonte

The correct answer is chosen by the method of scientific poke:

{ 
  loader: 'css-loader',
  options: {
   modules: {
      mode: 'local',
      exportLocalsConvention: 'camelCase'
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question