JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 94296
  • Score
    100M100P100Q13568F
  • License CC0-1.0

Use variables, mixins, conditionals, and other goodies in your CSS

Package Exports

  • precss

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (precss) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

PreCSS Build Status

PreCSS is a tool that allows you to use preprocessor-like markup in your CSS files.

The syntax allows you to use variables, mixins, conditionals, and other goodies.

Variables

/* before */

$blue: #056ef0;
$column: 200px;

.menu {
    width: calc(4 * $column);
}

.menu_link {
    background: $blue;
    width: $column;
}

/* after */

.menu {
    width: calc(4 * 200px);
}

.menu_link {
    background: #056ef0;
    width: 200px;
}

Conditionals

/* before */

.foo {
    @if 3 < 5 {
        background: green;
    }
    @else {
        background: blue;
    }
}

/* after */

.foo {
    background: green;
}
/* before */

@for $i from 1 to 3 {
    .b-$i { width: $(i)px; }
}

/* after */

.b-1 {
    width: 1px
}
.b-2 {
    width: 2px
}
.b-3 {
    width: 3px
}
/* before */

@each $icon in (foo, bar, baz) {
    .icon-$(icon) {
        background: url('icons/$(icon).png');
    }
}

/* after */

.icon-foo {
    background: url('icons/foo.png');
}

.icon-bar {
    background: url('icons/bar.png');
}

.icon-baz {
    background: url('icons/baz.png');
}

Mixins

/* before */

@define-mixin icon $name {
    padding-left: 16px;

    &::after {
        content: "";
        background-url: url(/icons/$(name).png);
    }
}

.search {
    @mixin icon search;
}

/* after */

magic {}

Imports

/* Before */

@import "partials/_base.css"; /* Contents of _base: `body { background: black; }` */


/* After */

body { background: black; }

Usage

You just need to follow these two steps to use PreCSS:

  1. Add PostCSS to your build tool.
  2. Add PreCSS as a PostCSS process.
npm install precss --save-dev

Node

postcss([ require('precss')({ /* options */ }) ])

Grunt

Add Grunt PostCSS to your build tool:

npm install precss --save-dev

Enable PreCSS within your Gruntfile:

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
    postcss: {
        options: {
            processors: [
                require('precss')({ /* options */ })
            ]
        },
        dist: {
            src: 'css/*.css'
        }
    }
});

Options

...