Code Monkey home page Code Monkey logo

Comments (3)

gravyraveydavey avatar gravyraveydavey commented on August 28, 2024

Also having this issue. When using Gulp to process several CSS files (after all other processing), the media query extraction is compounding into the subsequent files - like a buffer isn't being cleared after each file has finished being processed.

@hamsterkacke my work around was to make a series gulp task (rather than async) for processing the files entirely separately.

// after all SCSS compilation and other processing has happened

// task for splitting media queries out on a specific file passed as an argument
const splitMediaQueries = ( file ) => {

    const extractMediaQueryOptions = {
        queries: project.mediaQueryExtract.queries,
        output: {
            path: output.files + project.styles.dist + "/split/",
        },
        extractAll: false,
        stats:  true,
    }

    return gulp
        .src( output.files + project.styles.dist + "purged/" + file )
        .pipe( postcss( [ extractMediaQuery( extractMediaQueryOptions ) ] ) )
        .pipe( gulp.dest( output.files + project.styles.dist + "split/" ) );
};

// wrapper for primary stylesheet
const splitStyles = () => {
    return splitMediaQueries( 'style.css' );
}
// wrapper for critical, inline stylesheet
const splitHeadInline = () => {
    return splitMediaQueries( 'head-inline.css' );
}

// series task to process the two stylesheets sequentially 
const sequenceSplitStyles = gulp.series( splitStyles, splitHeadInline );

// the series for all style processing 
const sequenceStyles = gulp.series( styles, purgeStyles, sequenceSplitStyles, htdocs, purgeRejected );

// export the whole chain as a task
exports.styles = sequenceStyles;

Slower processing, but gets the extraction working!

from postcss-extract-media-query.

SassNinja avatar SassNinja commented on August 28, 2024

Hey folks,

sorry for the late response

I've tried to understand your problem - however I'm afraid I'm unable to reproduce what you described.
Have you seen my example for gulp?

I modified it to process more than one CSS file and the result remains the same, meaning it's working as expected without mixing up different files. This is how my files looked:

// src/one.css
.one { display: none; }

@media screen and (min-width: 1024px) {
  .one { display: block; }
}

// src/two.css
.two { display: none; }

@media screen and (min-width: 1024px) {
  .two { display: block; }
}

Afterwards it emits four files to the dist folder with the expected content.
If I change my test files into SCSS and add gulp-sass to the pipeline, it doesn't change the result.

Therefore I'm afraid I cannot do anything as it's looking good for me.
Could you provide full gulp example?

from postcss-extract-media-query.

Neibaf avatar Neibaf commented on August 28, 2024

Hello @SassNinja,

I think i have the same issue.

If you look at your file two-1024px.css, it has this rules

@media screen and (min-width: 1024px) {
  .one { display: block; }
  .two { display: block; }
}

But it should be

@media screen and (min-width: 1024px) {
  .two { display: block; }
}

from postcss-extract-media-query.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.