K
K
Kappy2019-07-20 16:40:50
typescript
Kappy, 2019-07-20 16:40:50

How to make friends modules with global css?

Good afternoon .
I decided to make module css friends with the ant design library.
Used to use create - react - app. Now I decided to slowly delve into the knowledge of the collectors.
I set up the whole project, but there is one problem, the styles are integrated in different ways.
Using style loader and css loader, in the following context

{
                test: /\.css$/,
                use: [
                    { loader: 'style-loader' },
                    { loader: 'css-loader', options: { modules: true } },
                ],
            },

5d3316a5aabca822897524.png
It seems that classes are installed, but without styles, but everything works if you remove the following flag in the config But without a module
options: { modules: true }
5d33172079b6a246594337.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kappy, 2019-07-20
@KappyJS

While writing, I solved the problem

const cssRegex = /\.css$/;
const cssModuleRegex = /\.module\.css$/;

 {
                test: cssRegex,
                exclude: cssModuleRegex,
                use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
            },
            {
                test: cssModuleRegex,
                use: [{ loader: 'style-loader' },
                    {
                        loader: 'css-loader',
                        options: {
                            modules: true,
                        },
                    },
                ],
            },

Maybe someone will help

D
Dmitry Belyaev, 2019-07-20
@bingo347

Default modules, when requested with ?no-module - no modules

{
  test:  /\.css$/,
  oneOf: [{
    resourceQuery: /no-module/,
    use: [{loader: 'style-loader'}, {loader: 'css-loader'}]
  }, {
    use: [{loader: 'style-loader'}, {loader: 'css-loader', options: {modules: true}}]
  }]
}

Without default modules, when requested with ?module - module
{
  test:  /\.css$/,
  oneOf: [{
    resourceQuery: /module/,
    use: [{loader: 'style-loader'}, {loader: 'css-loader', options: {modules: true}}]
  }, {
    use: [{loader: 'style-loader'}, {loader: 'css-loader'}]
  }]
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question