• Stars
    star
    285
  • Rank 145,115 (Top 3 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PostCSS adapter for Stylus

PostStylus

NPM version NPM downloads Build Status

PostStylus is a PostCSS adapter for Stylus. It allows you to use any PostCSS plugin as a transparent Stylus plugin, and do custom post-processing of Stylus output.

It loads PostCSS processors into Stylus just before the output CSS is compiled to file.

Inspired by autoprefixer-stylus

Contents

Install

$ npm install --save-dev poststylus

Usage

Use poststylus as a regular stylus plugin and pass it an array of PostCSS plugins you have installed, either as strings or functions.

stylus(css).use(poststylus([
  'autoprefixer',
  'rucksack-css'
]))

Gulp

var gulp = require('gulp'),
    stylus = require('gulp-stylus'),
    poststylus = require('poststylus'),
    autoprefixer = require('autoprefixer'),
    rucksack = require('rucksack-css');

gulp.task('stylus', function () {
  gulp.src('style.styl')
    .pipe(stylus({
      use: [
        poststylus([ autoprefixer, rucksack ])
      ]
    }))
    .pipe(gulp.dest('.'))
});

gulp.task('default', ['stylus']);

Grunt

grunt-contrib-stylus doesn't support passing arguments to plugins, so you have to wrap PostStylus in a function and return it

var postcss = function(){
  return require('poststylus')(['autoprefixer', 'rucksack-css']);
}

module.exports = function(grunt) {

  grunt.initConfig({

    stylus: {
      compile: {
        options: {
          use: [postcss]
        },
        files: {
          'style.css': 'style.styl'
        }
      }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-stylus');

};

Webpack

Use stylus-loader with PostStylus as a plugin in your webpack.conf.js

var poststylus = require('poststylus'),
    webpack = require('webpack');

module: {
  loaders: [
    { test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' }
  ]
},
stylus: {
  use: [
    poststylus([ 'autoprefixer', 'rucksack-css' ])
  ]
}

If you are using webpack 2, use LoaderOptionsPlugin to set options

module: {...},
plugins: [
  new webpack.LoaderOptionsPlugin({
    options: {
      stylus: {
        use: [poststylus([ 'autoprefixer', 'rucksack-css' ])]
      }
    }
  })
]

CLI

To use PostStylus on the Stylus CLI, pass poststylus to --use, and PostCSS plugins to --with:

$ stylus --use ./node_modules/poststylus --with "['autoprefixer']" --out test.css < test.styl

Passing Arguments to Plugins

If you need to pass arguments to a PostCSS plugin require() it and pass that function to PostStylus

var autoprefixer = require('autoprefixer');

stylus(css).use([
  poststylus([
    autoprefixer({ browsers: ['ie 8'] })
  ])
])

To pass arguments to PostCSS plugins on the CLI, you'll need to prefix require() with $PWD, since the stylus executable runs globally, while your plugins are (probably) installed locally:

stylus --use ./node_modules/poststylus --with "[require('${PWD}/node_modules/autoprefixer')({ browsers: ['ie 8'] })]" --out test.css < test.styl

Custom Processing

Do custom post-processing of Stylus output by declaring an on-the-fly PostCSS plugin

var myPostcss = postcss.plugin('custom', function() {
  return function (css) {
    // PostCSS processing here
  };
});

// Pipe it into poststylus
stylus(css).use(poststylus([myPostcss()]));

Refer to the [PostCSS Docs][postcss-link] for more on writing plugins.

Warning Handler

By default, if any of your PostCSS plugins raise a warning it will be displayed using console.error. You can override this behaviour by passing a function as the second argument to PostStylus.

stylus(css).use(poststylus([
    'autoprefixer',
    'rucksack-css'
], function(message) {
    console.info(message);
}));

Asynchronous Processing

Unfortunately the Stylus end event that PostStylus uses to pass back post-processed CSS doesn't accept a callback, so until this bug is patched upstream PostStylus cannot work with asynchronous PostCSS processing.


MIT Β© Sean King

More Repositories

1

rucksack

A little bag of CSS superpowers, built on PostCSS
JavaScript
1,849
star
2

postcss-responsive-type

Automagical responsive typography, built on PostCSS
JavaScript
370
star
3

postcss-hexrgba

PostCSS plugin that adds shorthand hex methods to rgba() values
JavaScript
70
star
4

postcss-fontpath

PostCSS plugin to automatically generate font-face src sets based on a path to font files
JavaScript
55
star
5

postcss-alias

PostCSS plugin that allows you to create aliases for CSS properties
JavaScript
47
star
6

postcss-clearfix

PostCSS plugin that adds a 'fix' argument to the 'clear' property
JavaScript
47
star
7

wordprismic

Utility to import existing Wordpress blogs into the Prismic.io content platform
JavaScript
31
star
8

postcss-position

PostCSS plugin that adds shorthand declarations for position attributes
JavaScript
25
star
9

laggard

Automatically generate CSS fallbacks for legacy browsers, built on PostCSS
JavaScript
23
star
10

svelte-gallery

Intelligent masonry style photo gallery that maintains image aspect ratios in perfect rows
JavaScript
21
star
11

satchel

The little bag of CSS-in-JS superpowers
TypeScript
16
star
12

postcss-input-style

PostCSS plugin that adds new pseudo-elements for easily styling the inner elements of inputs
JavaScript
16
star
13

react-portal-overlay

Lightweight fullscreen overlays using React portals
TypeScript
13
star
14

generator-web-component

Quickly scaffold powerful web components with Yeoman
JavaScript
12
star
15

postcss-subgrid

PostCSS plugin that shims some basic behaviour of the proposed CSS subgrid spec
JavaScript
10
star
16

svelte-meta

Easily generate SEO metadata for Svelte
Svelte
10
star
17

juli-cli

CLI tool to generate native web apps using Juli
Shell
4
star
18

svelte-imgix

Svelte action for responsive, lazily-loaded images with Imgix
TypeScript
4
star
19

lazy-import

Declaratively import HTML components when you're ready to use them
HTML
3
star
20

prismic-apollo-introspect

Prismic introspection utility for generating fragment types for Apollo
JavaScript
3
star
21

svelte-hamburger

Animated hamburger icon for svelte
Svelte
3
star
22

the-marketer

In a world overrun with angry consumers, only one person can save us
GDScript
3
star
23

gatsby-boilerplate

Opinionated and configurable boilerplate to quickly scaffold progressive, lightweight Gatsby projects
TypeScript
2
star
24

rucksackcss.org

Website for Rucksack
CSS
2
star
25

satchel-docs

Satchel's documentation, hosted by Gitbook
1
star
26

react-hamburger-icon

Featherweight animated hamburger icon for React
TypeScript
1
star
27

svelte-boilerplate

Boilerplate for modern distributable svelte components
TypeScript
1
star
28

gatsby-plugin-notify

Gatsby plugin that adds system notifications to your development build
JavaScript
1
star
29

react-component-boilerplate

Lightweight boilerplate for scaffolding modern React components
JavaScript
1
star