← All tools

csso-cli

Popularity 65 Updated Development & Build

Command line interface for CSSO

npmauto-collected

Installation

npm
npm install -g csso-cli

Install with npm.

Command line interface for CSSO.

  • Install
  • Usage
  • Source maps
  • Usage data
  • Debugging
  • Related projects
  • License

Install

npm install -g csso-cli

Usage

Usage:

    csso [input] [options]

Options:

        --comments <value>             Comments to keep: exclamation (default), first-exclamation or none
        --debug [level]                Output intermediate state of CSS during a compression
    -d, --declaration-list             Treat input as a declaration list
        --force-media-merge            Enable unsafe merge of @media rules
    -h, --help                         Output usage information
    -i, --input <filename>             Input file

-o, --output <filename Output file (result outputs to stdout if not set) --no-restructure Disable structural optimisations -s, --source-map <destination Generate source map: none (default), inline, file or <filename --stat Output statistics in stderr -u, --usage <filename Usage data file -v, --version Output version --watch Watch source file for changes


Some examples:

csso in.css ...output result in stdout...

csso in.css --output out.css

echo '.test { color: #ff0000; }' | csso .test{color:red}

cat source1.css source2.css | csso | gzip -9 -c production.css.gz


### Source maps

Source map doesn't generate by default. To generate map use `--source-map` CLI option, that can be:

- `none` (default) – don't generate source map
- `inline` – add source map into result CSS (via `/*# sourceMappingURL=application/json;base64,... */`)
- `file` – write source map into file with same name as output file, but with `.map` extension (in this case `--output` option is required)
- any other values treat as filename for generated source map

Examples:

csso my.css --source-map inline csso my.css --output my.min.css --source-map file csso my.css --output my.min.css --source-map maps/my.min.map


Use `--input-source-map` option to specify input source map if needed. Possible values for option:

- `auto` (default) - attempt to fetch input source map by follow steps:
  - try to fetch inline map from input
  - try to fetch source map filename from input and read its content
  - (when `--input` is specified) check file with same name as input file but with `.map` extension exists and read its content
- `none` - don't use input source map; actually it's using to disable `auto`-fetching
- any other values treat as filename for input source map

Generally you shouldn't care about the input source map since defaults behaviour (`auto`) covers most use cases.

Usage data

CSSO can use data about how CSS is using for better compression. File with this data (JSON format) can be set using --usage option. Read more about Usage data in CSSO repository.