Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PostCSS adapter for Stylus

NotificationsYou must be signed in to change notification settings

madeleineostoja/poststylus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM versionNPM downloadsBuild Status

PostStylus is aPostCSS 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 byautoprefixer-stylus

Contents

Install

$ npm install --save-dev poststylus

Usage

Usepoststylus 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

vargulp=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

varpostcss=function(){returnrequire('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

Usestylus-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, useLoaderOptionsPlugin to set options

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

CLI

To use PostStylus on the Stylus CLI, passpoststylus 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 pluginrequire() it and pass that function to PostStylus

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

To pass arguments to PostCSS plugins on the CLI, you'll need to prefixrequire() with$PWD, since thestylus 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

varmyPostcss=postcss.plugin('custom',function(){returnfunction(css){// PostCSS processing here};});// Pipe it into poststylusstylus(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 usingconsole.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 Stylusend event that PostStylus uses to pass back post-processed CSS doesn't accept a callback, so untilthis bug is patched upstream PostStylus cannot work with asynchronous PostCSS processing.


MIT ©Sean King

About

PostCSS adapter for Stylus

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2026 Movatter.jp