PHP 7 Script to Compile SCSS to CSS Code in Command Line Using scssphp Library Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments



scssphp is a compiler for SCSS written in PHP.

SCSS is a CSS preprocessor language that adds many features like variables, mixins, imports, nesting, color manipulation, functions, and control directives.

scssphp is ready for inclusion in any project. It includes a command line tool for running the compiler from a terminal/shell or script.




You can always download the latest version here: scssphp-v1.10.3.tar.gz

You can also find the latest source online:

If you use Packagist for installing packages, then you can update your composer.json like so:





Command Line Tool

A really basic command line tool is included for integration with scripts. It is called pscss. It reads SCSS from either a named input file or standard in, and returns the CSS to standard out.

Usage: bin/pscss [options] [input-file] [output-file]


If passed the flag -h (or --help), input is ignored and a summary of the command’s usage is returned.

If passed the flag -v (or --version), input is ignored and the current version is returned.

The flag -s (or --style) can be used to set the output style:

The flag -I (or --load_path) can be used to set import paths for the loader. On Unix/Linux systems, the paths are colon separated. On Windows, they are separated by a semi-colon.

SCSSPHP Library Reference

To use the scssphp library either require or use your composer generated auto-loader, and then invoke the \ScssPhp\ScssPhp\Compiler class:






The compileString method takes the SCSS source code as a string and an optional path of the input file (to resolve relative imports), and returns a CompilationResult value object containing the CSS and some additional data. If there is an error when compiling, a \ScssPhp\ScssPhp\Exception\SassException is thrown with an appropriate message.


Leave a Reply