0
votes

I have the following configuration where I have an EventInfoCard. When it's in a preloading state, it renders a different component that inherits a lot of CSS from the parent. I am using postcss-cssnext variables and this composes function does not seem to play nicely with the css-loader.

EventInfoCard.css

@import '../constants.css';

.root {

}

.thumbnail {
    display: block;
    width: 100%;
    height: 0px;
    padding-bottom: 56%;
    position: relative;
    overflow: hidden;
    border-radius: var(--xxxs)px;
}

.notification {
    border-radius: var(--xxxs)px;
    font-size: 12px;
    display: inline-block;
    height: var(--s)px;
    padding: 0 var(--xxs)px;
    line-height: var(--s)px;
    text-transform: uppercase;
    font-weight: var(--weight-medium);
    margin-right: var(--xxs)px;
}

.description {
    letter-spacing: -0.1px;
    margin-top: 7px;
}

EventInfoCardPreloading.css

@import '../constants.css';

.root {
    background: blue;
}

.thumbnail {
    composes: thumbnail from './InfoCard.css';
    background-color: var(--tones-lightest);
}

.description {
    composes: description from './InfoCard.css';
}

Although now it seems to be bringing in the EventInfoCard CSS and not transforming the variables, which ends up with this invalid CSS as seen below. So what am I doing wrong? I thought that composes would only grab the classname and not bring in the file.

enter image description here

postcss config:

const path = require('path')

module.exports = {
    plugins: {
        'postcss-partial-import': {},
        'postcss-mixins': {
            mixinsDir: path.join(__dirname, 'statics', 'mycujoo-theme', 'mixins')
        },
        'postcss-nested': {},
        'postcss-cssnext': {
            browsers: ['last 2 versions', '> 5%'],
        }
    }
}

webpack loader config:

    test: /\.css$/,
    use: extractCSS.extract({
        fallback: 'style-loader',
        use: [
            { loader: 'css-loader', options: { modules: true, localIdentName: '[name]__[local]___[hash:base64:5]' } },
            { loader: 'postcss-loader' }
        ]
    }),
1

1 Answers

0
votes

Since your configuration is making us of CSS Modules and postcss-loader, it should also declare a importLoaders option to make postcss-loader and css-loader with CSS modules enabled work together.

test: /\.css$/,
use: extractCSS.extract({
    fallback: 'style-loader',
    use: [
        { loader: 'css-loader', options: { modules: true, importLoaders: 1, localIdentName: '[name]__[local]___[hash:base64:5]' } },
        { loader: 'postcss-loader' }
    ]
}),