Skip to content

Media queries from other files gets merged in the current file #2

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

Closed
htshah opened this issue Feb 28, 2020 · 0 comments · Fixed by #3
Closed

Media queries from other files gets merged in the current file #2

htshah opened this issue Feb 28, 2020 · 0 comments · Fixed by #3
Labels
bug Something isn't working
Milestone

Comments

@htshah
Copy link

htshah commented Feb 28, 2020

Below is the styles task from my gulpfile.js. My project has multiple css files which gets outputted in the assets folder. When the task is executed, I don't know why this plugin merges all the media queries from each file and outputs it to each file.

const postcss = require("gulp-postcss");
const postcssPresetEnv = require("postcss-preset-env");
const cssnano = require("cssnano");
const purgecss = require("gulp-purgecss");
const purgecssWordpress = require('purgecss-with-wordpress');
const postcssNormalize = require("postcss-normalize");
const atImport = require("postcss-easy-import");
const combineMediaQueries = require("postcss-combine-media-query");

function styles() {
  const sourcemaps = require("gulp-sourcemaps");

  const postcssProcessors = [
    atImport({
      root: "./src/css",
      path: "./src/css"
    }),
    postcssNormalize({ browsers: ["defaults", "IE >= 10"] }),
    require("postcss-nested")(),
    postcssPresetEnv({
      stage: 0,
      preserve: false,
      browsers: ["defaults", "IE >= 10"],
      autoprefixer: isProduction,
      features: { "nesting-rules": false },
      fontFace: true,
    }),
    combineMediaQueries()
  ];

  if (isProduction) {
    postcssProcessors.push(
      cssnano(),
    );
  }

  return src([
    "src/css/**/!(_)*.css", // select all css files
    "!src/css/**/_*/", // exclude all folder starting with _
    "!src/css/**/_*/**/*" //exclude files/subfolders in folders starting with '_'
  ])
    .pipe(gulpIf(!isProduction, sourcemaps.init()))
    .pipe(
      postcss(postcssProcessors, {
        parser: require("postcss-comment") // To handle inline comments
      })
    )
    .pipe(gulpIf(!isProduction, sourcemaps.write(".")))
    .pipe(dest("assets/css"))
    .pipe(gulpIf(!isProduction, browserSync.stream()));
}
@SassNinja SassNinja added the bug Something isn't working label Mar 10, 2020
@SassNinja SassNinja added this to the 1.0.1 milestone Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants