Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules get applied every time a new file is processed #31

Open
hamsterkacke opened this issue Sep 3, 2020 · 3 comments
Open

Rules get applied every time a new file is processed #31

hamsterkacke opened this issue Sep 3, 2020 · 3 comments
Labels
question Further information is requested

Comments

@hamsterkacke
Copy link

Hey!

I have a simple gulp process:

`gulp.task('css', () => {

const plugins = [
	extractMediaQuery({
		output: {
			path: dirs.dest + '/components',
		}
	})
];
return gulp.src('./dist/components/*.css')
	.pipe(postcss(plugins))
	.pipe(gulp.dest('./dist/components'));

});`

The CSS is already process from sass to css in a step before. So i have various css files in my dist/components folder.
No i want to run extractMediaQuery on it. This works.

BUT there is a major drawback:

The first file, that has extractable stuff in it, gets extracted fine. But on the next file, that has some media queries, the rules from the first extraction are applied again. And so on and so on.

So my first media css file is 318byte. The second one then too, even if the main css file doesn't have media queries. Next one is content + 318byte and so on and so on,

Not sure what i am doing wrong. Why is postcss applying the same stuff over and over again till the last file?

Here are as an example the first process file and the last process file.

@media screen and (min-width:768px){.badge .rating{padding:14px 0}} @media screen and (min-width:768px){.badge .text .image img{width:23px}} @media screen and (min-width:768px){.badge .text .rating-in-words .big{font-size:18px}} @media screen and (min-width:768px){.badge .text .rating-in-words .small{font-size:12px}}

@media screen and (min-width:768px){.badge .rating{padding:14px 0}} @media screen and (min-width:768px){.badge .text .image img{width:23px}} @media screen and (min-width:768px){.badge .text .rating-in-words .big{font-size:18px}} @media screen and (min-width:768px){.badge .text .rating-in-words .small{font-size:12px}} ......redacted by me.... @media screen and (min-width:768px){.toc{position:-webkit-sticky;position:sticky;top:88px}}

As you can see, the first four lines are reapplied.

Any help on that?

@gravyraveydavey
Copy link

gravyraveydavey commented May 19, 2021

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!

@SassNinja
Copy link
Owner

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?

@SassNinja SassNinja added the question Further information is requested label Oct 10, 2021
@Neibaf
Copy link

Neibaf commented Mar 7, 2022

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; }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants