|
1 | | -[![npm][npm]][npm-url] |
2 | | -[![node][node]][node-url] |
3 | | -[![deps][deps]][deps-url] |
4 | 1 | [![tests][tests]][tests-url] |
| 2 | +[![cover][cover]][cover-url] |
| 3 | +[![deps][deps]][deps-url] |
| 4 | +[![npm][npm]][npm-url] |
5 | 5 | [![code style][style]][style-url] |
6 | 6 | [![chat][chat]][chat-url] |
7 | 7 |
|
|
13 | 13 | <h1>PostCSS CLI</h1> |
14 | 14 | </div> |
15 | 15 |
|
16 | | -## Install |
| 16 | +## Installation |
17 | 17 |
|
18 | 18 | ```bash |
19 | 19 | npm i -D postcss-cli |
20 | 20 | ``` |
21 | 21 |
|
22 | 22 | ## Usage |
23 | 23 |
|
24 | | -```bash |
25 | | -postcss [options] [input] [-o output|-d output-dir|-r] [--watch] |
| 24 | +``` |
| 25 | +postcss [input.css] [OPTIONS] [--output|-o output.css] [--watch] |
| 26 | +
|
| 27 | +Options: |
| 28 | + -o, --output Output file [string] |
| 29 | + -d, --dir Output directory [string] |
| 30 | + -r, --replace Replace (overwrite) the input file [boolean] |
| 31 | + -u, --use List of postcss plugins to use [array] |
| 32 | + -p, --parser Custom postcss parser [string] |
| 33 | + -t, --stringifier Custom postcss stringifier [string] |
| 34 | + -s, --syntax Custom postcss syntax [string] |
| 35 | + -w, --watch Watch files for changes and recompile as needed [boolean] |
| 36 | + -x, --extension Override the output file extension [string] |
| 37 | + -e, --env A shortcut for setting NODE_ENV [string] |
| 38 | + -c, --config Set a custom path to look for a config file [string] |
| 39 | + -m, --map Create an external sourcemap |
| 40 | + --no-map Disable the default inline sourcemaps |
| 41 | + -h, --help Show help [boolean] |
| 42 | + -v, --version Show version number [boolean] |
| 43 | +
|
| 44 | +Examples: |
| 45 | + postcss input.css -o output.css Basic usage |
| 46 | + cat input.css | postcss -u Piping input & output |
| 47 | + autoprefixer > output.css |
| 48 | +
|
| 49 | +If no input files are passed, it reads from stdin. If neither -o, --dir, or |
| 50 | +--replace is passed, it writes to stdout. |
| 51 | +
|
| 52 | +If there are multiple input files, the --dir or --replace option must be passed. |
26 | 53 | ``` |
27 | 54 |
|
28 | | -## Options |
29 | | - |
30 | | -|Name|Default|Description| |
31 | | -|:--:|:-----:|:----------| |
32 | | -|**`--dir/-d`**|`undefined`|Directory destination| |
33 | | -|**`--ext/-ex`**|`undefined`|Change Output File Extension| |
34 | | -|**`--output/-o`**|`process.stdout`|File destination| |
35 | | -|**`--replace/-r`**|`undefined`|Replace file(s) with output| |
36 | | -|**`--parser/-p`**|`undefined`|[Custom Parser][parser] (e.g SugarSS)| |
37 | | -|**`--syntax/-s`**|`undefined`|[Custom Syntax][syntax] (e.g Midas)| |
38 | | -|**`--stringifier/-t`**|`undefined`|[Custom Stringifier][stringifier] (e.g ..)| |
39 | | -|**`--map/-m`**|`{ inline: false }`|Enable external Sourcemaps| |
40 | | -|**`--no-map`**|`false`|Disable Sourcemaps| |
41 | | -|**`--watch/-w`**|`false`|Watch files && `postcss.config.js`for changes| |
42 | | -|**`--help/-h`**|`undefined`|CLI Usage| |
43 | | -|**`--version/-v`**|`undefined`|CLI Version| |
44 | | - |
45 | | -[parser]: https://github.com/postcss/postcss#custom-syntaxes |
46 | | - |
47 | | -#### `--map|-m` |
| 55 | +For more details on custom parsers, stringifiers and syntaxes, see the [postcss docs](https://github.com/postcss/postcss#syntaxes). |
48 | 56 |
|
49 | | -Activate sourcemaps generation. By default inline sourcemaps are generated. |
50 | | -You can use [advances source map options][sourcemaps]. |
| 57 | +## Configuration |
51 | 58 |
|
52 | | -#### [`--config|-c`](https://github.com/michael-ciniawsky/postcss-load-config) |
| 59 | +If you need to pass options to your plugins, or have a long plugin chain, you'll want to use a configuration file. |
53 | 60 |
|
54 | | -```bash |
55 | | -postcss -c|--config path/to/postcss.config.js |
56 | | -``` |
57 | | -**postcss.config.js** |
| 61 | +Example `postcss.config.js`: |
58 | 62 |
|
59 | 63 | ```js |
60 | | -module.exports = (ctx) => ({ |
61 | | - parser: ctx.options.parser ? 'sugarss' : false, |
62 | | - map: ctx.env === 'development' ? 'inline' : false, |
63 | | - plugins: { |
64 | | - 'postcss-import': { root: ctx.file.dirname }, |
65 | | - 'postcss-nested': {}, |
66 | | - 'cssnano': ctx.env !== 'development' ? {} : false |
67 | | - } |
68 | | -}) |
| 64 | +module.exports = () => { |
| 65 | + parser: 'sugarss', |
| 66 | + plugins: [ |
| 67 | + require('postcss-import')({ /* Options */ }), |
| 68 | + require('postcss-url')({ |
| 69 | + url: 'copy', |
| 70 | + useHash: true |
| 71 | + }) |
| 72 | + ] |
| 73 | +} |
69 | 74 | ``` |
70 | 75 |
|
| 76 | +Configuration files are handled by [postcss-load-config](https://github.com/michael-ciniawsky/postcss-load-config). Refer to the docs there for more details. |
| 77 | + |
71 | 78 |
|
72 | 79 | [npm]: https://img.shields.io/npm/v/postcss-cli.svg |
73 | 80 | [npm-url]: https://npmjs.com/package/postcss-cli |
74 | 81 |
|
75 | | -[node]: https://img.shields.io/node/v/<name>-loader.svg |
76 | | -[node-url]: https://nodejs.org |
77 | | - |
78 | 82 | [deps]: https://img.shields.io/gemnasium/postcss/postcss-cli.svg |
79 | 83 | [deps-url]: https://gemnasium.com/postcss/postcss-cli |
80 | 84 |
|
|
0 commit comments