gasolin / provecss

Write future proved CSS from now
MIT License
1 stars 3 forks source link

provecss

DEPRECATED, please use postcss-cssnext instead

Write future-proved CSS from now.

Build Status NPM version Dependency Status Code Climate

provecss let us able to use @import, @media queries, variables in mobile-first webapp development without worring the performance. provecss could preprocess the origin css file and generate backward compatible css styles.

Features

Support test cases demostrate the input and output result of provecss.

Import inlining

Thanks to rework-importer

Input files:

imprt.css

@import url("imprt_core.css");
@import url("imprt_large.css");
@import url("imprt_xlarge.css");

imprt_core.css

headers {
  background-color: orange;
}

imprt_large.css

@media (min-width: 768px) {
  headers {
    background-color: black;
  }
}

imprt_xlarge.css

@media (min-width: 1024px) {
  headers {
    background-color: red;
  }
}

Output:

headers {
  background-color: orange;
}

@media (min-width: 768px) {
  headers {
    background-color: black;
  }
}

@media (min-width: 1024px) {
  headers {
    background-color: red;
  }
}

Import filtering

Pass import_filter option as ['core', 'large'] to filter out other styles.

Output:

headers {
  background-color: orange;
}

@media (min-width: 768px) {
  headers {
    background-color: black;
  }
}

Media Query matching

An alternative way is to pass media_match option as filter creteria.

Input with { width: '1024px', height: '768px' } to match proper size of @media.

Output:

headers {
  background-color: orange;
}

@media (min-width: 1024px) {
  headers {
    background-color: red;
  }
}

Media Query extracting

Pass extra media_extract option as true

Output:

headers {
  background-color: orange;
}

headers {
  background-color: red;
}

In result, the was-@media section just overwrited the origin style.

CSS Variables replacing

Thanks to rework-vars

Pass vars option as true to opt-in variabls replacing.

Input:

:root {
  --main-color: orange;
}

body {
  color: var(--main-color);
}

Output:

body {
  color: orange;
}

Usage (in node)

You can install provecss via npm.

npm install provecss --save-dev

provecss input/output are strings. So you could chain it in any preprocessing position.

var provecss = require('provecss');
var fs = require('fs');

// read file
var input = fs.readFileSync('imprt.css', 'utf8');
var output = provecss(input);

// write file
fs.writeFileSync('imprt.out.css', output);

To inline @import files, you could pass path option and provecss will search and inline import files in path's directory:

provecss(input, {path: 'test/features/imprt.css'});

Options

Usage (with grunt)

Grunt plugin is available in https://www.npmjs.org/package/grunt-provecss Pass same options as use in node.

Usage (in command line)

You can Run command in console

provecss source target [options]

For example

provecss color.css color.out.css [options]

Options

Credit

provecss is based on rework. Forked from myth and rework-importer to fit our needs.

License

MIT