postcss/postcss-cli

Name: postcss-cli

Owner: PostCSS

Description: CLI for postcss

Created: 2016-01-30 18:33:59.0

Updated: 2018-05-21 20:19:22.0

Pushed: 2018-05-16 01:21:39.0

Homepage:

Size: 242

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

npm node deps Greenkeeper badge tests cover chat

PostCSS CLI

Install

i -g|-D postcss-cli

Usage

e:
stcss [input.css] [OPTIONS] [-o|--output output.css] [--watch|-w]
stcss <input.css>... [OPTIONS] --dir <output-directory> [--watch|-w]
stcss <input-directory> [OPTIONS] --dir <output-directory> [--watch|-w]
stcss <input.css>... [OPTIONS] --replace

c options:
, --output   Output file                                            [string]
, --dir      Output directory                                       [string]
, --replace  Replace (overwrite) the input file                    [boolean]
map, -m      Create an external sourcemap
no-map       Disable the default inline sourcemaps
verbose      Be verbose                                            [boolean]
watch, -w    Watch files for changes and recompile as needed       [boolean]
env          A shortcut for setting NODE_ENV                        [string]

ons for when not using a config file:
, --use      List of postcss plugins to use                          [array]
parser       Custom postcss parser                                  [string]
stringifier  Custom postcss stringifier                             [string]
syntax       Custom postcss syntax                                  [string]

nced options:
ext     Override the output file extension; for use with --dir      [string]
base    Mirror the directory structure relative to this path in the output
        directory, for use with --dir                               [string]
poll    Use polling for file watching. Can optionally pass polling interval;
        default 100 ms
config  Set a custom path to look for a config file                 [string]

ons:
version  Show version number                                       [boolean]
, --help     Show help                                             [boolean]

ples:
stcss input.css -o output.css                       Basic usage
t input.css | postcss -u autoprefixer > output.css  Piping input & output

o input files are passed, it reads from stdin. If neither -o, --dir, or
place is passed, it writes to stdout.

here are multiple input files, the --dir or --replace option must be passed.

t files may contain globs. If you pass an input directory, it will process
files in the directory and any subdirectories.

?? More details on custom parsers, stringifiers and syntaxes, can be found here.

Config

If you need to pass options to your plugins, or have a long plugin chain, you'll want to use a configuration file.

postcss.config.js

le.exports = {
rser: 'sugarss',
ugins: [
require('postcss-import')({ ...options }),
require('postcss-url')({ url: 'copy', useHash: true })


Note that you can not set the from or to options for postcss in the config file. They are set automatically based on the CLI arguments.

Context

For more advanced usage it's recommend to to use a function in postcss.config.js, this gives you access to the CLI context to dynamically apply options and plugins per file

| Name | Type | Default | Description | | :——-: | :——–: | :——————————–: | :——————- | | env | {String} | 'development' | process.env.NODE_ENV | | file | {Object} | dirname, basename, extname | File | | options | {Object} | map, parser, syntax, stringifier | PostCSS Options |

postcss.config.js

le.exports = ctx => ({
p: ctx.options.map,
rser: ctx.file.extname === '.sss' ? 'sugarss' : false,
ugins: {
'postcss-import': { root: ctx.file.dirname },
cssnano: ctx.env === 'production' ? {} : false


?? If you want to set options via CLI, it's mandatory to reference ctx.options in postcss.config.js

css input.sss -p sugarss -o output.css -m

postcss.config.js

le.exports = ctx => ({
p: ctx.options.map,
rser: ctx.options.parser,
ugins: {
'postcss-import': { root: ctx.file.dirname },
cssnano: ctx.env === 'production' ? {} : false



This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.