CSSNext postcss-custom-media - unable to import medias from file with 'importFrom' option

1.7k views Asked by At

I'm trying to add customMedia option to my postcss-cssnext features config with importFrom file location, but that doesnt work and I dont have any errors on project build, only final Missing @custom-media definition for '--small-viewport'. The entire rule has been removed from the output. when I'm trying to use the media. How do I debug this?

module.exports = {
    plugins: [
        require('postcss-import')(),
        require('postcss-nested')(),
        require('postcss-simple-vars')({
            variables: {
                ...require('./src/ui/variables')
            }
        }),
        require('postcss-cssnext')({
            features: {
                customProperties: false,
                browsers: ['> 0.5%, last 2 versions, Firefox ESR, not dead'],
                customMedia: {
                    importFrom: require('path').join(__dirname, './src/ui/custom-media.css')
                }
            },
        }),
        require('cssnano')({
            autoprefixer: false,
            zindex: false,
            reduceIdents: false,
            discardComments: { removeAll: true },
            discardUnused: { fontFace: false },
            colormin: false,
        }),
    ]
};
2

There are 2 answers

0
godblessstrawberry On BEST ANSWER

Okay so as per postcss-custom-media CHANGELOG importFrom was added only in 7.0.0 while my cssnext uses 6.0.0. As CSSNext is deprecated I will switch to postcss-preset-env

3
Batyodie On

you know how to use custom media in postcss-preset-env, they work for me only if you create a custom media in the component and refer to it if I want to take custom media from index.css or vars.css they do not work , with variables everything is fine