Answer the question
In order to leave comments, you need to log in
How to properly convert css-loader settings from string to object?
There was a file webpackfile.js
with the following content:
// .....
return {
// ....
module: {
rules: [
// ...
{
test: /\.css$/,
loader: 'style-loader!css-loader?modules&localsConvention=camelCase'
},
// .....
]
},
// ....
};
loader
into an array use
. return {
// ...
module: {
rules: [
// ...
{
test: /\.css$/,
use: [{
loader: 'style-loader'
}, {
loader: 'css-loader',
options: {
// ???????
}
}]
},
// .....
]
},
// ....
};
options
instead 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
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 questionAsk a Question
731 491 924 answers to any question