Linux command
postcss 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Process CSS file
postcss [input.css] -o [output.css]
Use config file
postcss [input.css] -o [output.css] -c [postcss.config.js]
Watch for changes
postcss [input.css] -o [output.css] --watch
Process directory
postcss [src/] -d [dist/]
Use specific plugins
postcss [input.css] -o [output.css] -u [autoprefixer]
Replace file in place
postcss [style.css] --replace
With source maps
postcss [input.css] -o [output.css] --map
说明
postcss is a tool for transforming CSS with JavaScript plugins. Rather than being a preprocessor itself, it provides a framework where plugins perform specific transformations on the CSS abstract syntax tree. Popular plugins include Autoprefixer for adding vendor prefixes, cssnano for minification, and postcss-preset-env for using future CSS syntax today. Plugins are chained together in a configuration file (postcss.config.js) or specified on the command line. Each plugin receives the parsed CSS, applies its transformation, and passes the result to the next plugin. This modular approach allows teams to compose exactly the processing pipeline they need. Watch mode reprocesses files automatically when changes are detected, integrating into development workflows. Source maps preserve the mapping between transformed and original CSS for debugging in browser developer tools.
参数
- -o, --output _FILE_
- Output file.
- -d, --dir _DIR_
- Output directory.
- -c, --config _FILE_
- Config file path.
- -u, --use _PLUGINS_
- Plugins to use.
- -w, --watch
- Watch mode.
- --map
- Generate source maps.
- --replace
- Replace input files.
- --no-map
- Disable source maps.
- -v, --verbose
- Verbose output.
FAQ
What is the postcss command used for?
postcss is a tool for transforming CSS with JavaScript plugins. Rather than being a preprocessor itself, it provides a framework where plugins perform specific transformations on the CSS abstract syntax tree. Popular plugins include Autoprefixer for adding vendor prefixes, cssnano for minification, and postcss-preset-env for using future CSS syntax today. Plugins are chained together in a configuration file (postcss.config.js) or specified on the command line. Each plugin receives the parsed CSS, applies its transformation, and passes the result to the next plugin. This modular approach allows teams to compose exactly the processing pipeline they need. Watch mode reprocesses files automatically when changes are detected, integrating into development workflows. Source maps preserve the mapping between transformed and original CSS for debugging in browser developer tools.
How do I run a basic postcss example?
Run `postcss [input.css] -o [output.css]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -o, --output _FILE_ do in postcss?
Output file.