Giter VIP home page Giter VIP logo

postcss-media-variables's People

Contributors

iest avatar wolfgangkluge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

iest dogmar kritua

postcss-media-variables's Issues

Does postcss-media-variables work with precss?

I am running a series of PostCSS plugins in the order shown below. When using the postcss-media-variables, all media queries are removed from the output.

package.json script
postcss --use precss --use postcss-media-variables --use autoprefixer --use postcss-calc --use postcss-media-variables

css files
`.my-class {
padding-top: 0;
border-bottom: none;

@media (max-width: calc($(screen-sm-min) - 1)) {
    padding-left: 0;
    padding-right: 0;
}

}`

postcss-media-variables with mqpacker

Hello guys! I have a strange behaviour when I try to use these two packages. Here is my gulp-pipe task for postcss:

    .pipe(
      postcss([
        postcssimport(),
        mediavariables(),
        hexalpha(),
        autoprefixer(),
        mqpacker({
          sort: (a, b) => a.localeCompare(b),
        }),
        mediavariables(),
      ])
    )

The code I want to convert:

:root {
  --min-width: 200px;
}
@media (min-width: var(--min-width)) {
  body {
    background: red;
  }
}

If I use it this way, I get this result. I have "background: red" in the css bundle, but some of the media queries are undefined:

If I swap mqpacker with the mediavariables task, I get this result(there are no any info about "background: red"):
изображение

Could you tell me how I can fix it?

Is this package compatible with postcss-loader?

I cannot seem to get this plugin to work.

I'm using postcss-loader through webpack 2 and I have the following in my PostCSS config file:

module.exports = () => ({
  plugins: {
    'postcss-import': {},
    'postcss-media-variables': {},
    'postcss-cssnext': {
      browsers: ['last 2 versions']
    }
  }
});

Here are the version numbers of the packages I'm using:

"postcss-cssnext": "^2.10.0",
"postcss-import": "^9.1.0",
"postcss-loader": "^1.3.3"

The output of this results in the following:

::-postcss-media-variables {-postcss-media-run: 1 }
::-postcss-media-variables {-pcs-mv-40-12e: 500px }

@media (max-width:-pcs-mv-40-12e) {
  ::-postcss-media-variables {
    .zOWzDY-App-h1-heading {
      background: red;
    }
  }
}

I tried adding in the postcss-media-variables plugin twice in my PostCSS config file, but this didn't seem to make a difference.

Do you know of a way to get this working with postcss-loader?

Package is currently completely broken

Doesn't seem like the second run works anymore. Here's the example from README.md, shortened a little bit:

const postcss = require("postcss");
const mediaVariables = require("postcss-media-variables");
const css = `
	:root {
		--min-width: 1000px;
		--smallscreen: 480px;
	}
	@media (min-width: var(--min-width)) {}
`;
// Process your CSS
const output = postcss([
        mediaVariables(), // first run
        mediaVariables() // second run
    ])
    .process(css)
    .css;

console.log(output);

The output is ([email protected]):

        :root {
                --min-width: 1000px;
                --smallscreen: 480px;
        }
        @media (min-width: var(--min-width)) {}

and with the newest [email protected], the output is:

::-postcss-media-variables {
                /* If you can see this comment, you might have forgotten to add
postcss-media-variables to the plugin list for a second time.

Otherwise, it's a bug :) Sorry
Please report here: https://github.com/WolfgangKluge/postcss-media-variables/issues */
                -postcss-media-run: 1;
}
        :root {
                --min-width: 1000px;
                --smallscreen: 480px;
        }
        ::-postcss-media-variables {
                /* If you can see this comment, you might have forgotten to add
postcss-media-variables to the plugin list for a second time.

Otherwise, it's a bug :) Sorry
Please report here: https://github.com/WolfgangKluge/postcss-media-variables/issues */
}
        ::-postcss-media-variables {
                /* If you can see this comment, you might have forgotten to add
postcss-media-variables to the plugin list for a second time.

Otherwise, it's a bug :) Sorry
Please report here: https://github.com/WolfgangKluge/postcss-media-variables/issues */
}

bug customMedia preserve: true,

If customMedia option preserve: true error build. With option preserve: false good work. And necessarily import css variables in css file where used vars
Снимок

Cannot process nested variable correctly

We are using postcss-custom-media along with postcss-media-variables and postcss-custom-properties together in a monorepo setup.

We found out that our custom media query was not parsed correctly.
@media (--sm-and-below) was parsed to @media screen and (max-width: var(-screen-sm-max)).
@media (--sm-and-below) is defined as @custom-media --sm-and-below screen and (max-width: var(--screen-sm-max)); with --screen-sm-max defined somewhere else.

We ended up reordering the plugin like so and it worked.

  • postcss-custom-media (this one got moved to the first)
  • postcss-media-variables (first occurence)
  • postcss-custom-properties
  • postcss-media-variables (second occurence)

Not sure if my setup was wrong or the problem lies with one of the plugins we use.

Use properties for different stages of running

Use properties for different stages of running to avoid confusion and add more composibility, flexibility: mediaVariables.inspect() and mediaVariables.resolve()

var postcss = require('postcss');

var mediaVariables = require('postcss-media-variables');

var mycss = fs.readFileSync('input.css', 'utf8');

// Process your CSS
var output = postcss([
        mediaVariables.inspect(), // first run
       // ...
        mediaVariables.resolve() // second run
    ])
    .process(mycss)
    .css;

console.log(output);

Tests pass but I am getting `::-postcss-media-variables` in output

I am trying to use this with PostCSS v5 before the upgrade (should work, just deprecated method warnings).

I ran the tests on this repo and they pass but when I try to use this plugin, it keeps ::-postcss-media-variables bugs in the output. It seems to happen whether I run the other plugins in the stack or not.

"devDependencies": {
    "postcss": "^5.0.6",
    "postcss-calc": "^5.0.0",
    "postcss-css-variables": "^0.5.0",
    "postcss-custom-media": "^5.0.0",
    "postcss-import": "^7.0.0",
    "postcss-media-variables": "^1.1.2"
}
'use strict';

let postcss = require('postcss');
let mediaVariables = require('postcss-media-variables');

let cssVariables = require('postcss-css-variables');
let calc = require('postcss-calc');
let customMedia = require('postcss-custom-media');

let warningToString = function(warning) {
    return warning.type + ': ' + warning.text;
};


let processor = postcss(
    mediaVariables(),
    /* */
    customMedia(),
    cssVariables(),
    calc(),
    /* */
    mediaVariables()
);

let input = `
:root {
    --min-width: 1000px;
}
@media (max-width: calc(var(--min-width) - 1px)) {}
`;

processor
    .process(input)
    .then(function (result) {
        let output = result.css;
        let warnings = result.warnings().map(warningToString).join('\n\n');

        console.log(output);
    });

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.