{"id":2730,"date":"2022-08-09T21:19:41","date_gmt":"2022-08-09T16:19:41","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=2730"},"modified":"2022-08-09T21:19:43","modified_gmt":"2022-08-09T16:19:43","slug":"php7-compile-scss-to-css-code-in-command-line-using-scssphp-library","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/","title":{"rendered":"PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library"},"content":{"rendered":"\n<p><strong>scssphp<\/strong>\u00a0is a free and open source compiler for\u00a0<a href=\"https:\/\/sass-lang.com\/\">SCSS<\/a>\u00a0that is written using PHP programming language.<\/p>\n\n\n\n<p>Basically, SCSS is a CSS preprocessor language that gives us additional features like variables, functions, mixins, imports, control directives, nesting, and color manipulation.<\/p>\n\n\n\n<p>You can easily use <strong>scssphp<\/strong>\u00a0in any existing or new PHP-based project. It is packed with a command line tool that enables us to execute the compiler from a terminal\/shell script.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install scssphp<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/github.com\/scssphp\/scssphp\/\">source code of scssphp<\/a> is available on GitHub. To install scssphp, simply select the <a href=\"https:\/\/github.com\/scssphp\/scssphp\/releases\">latest release<\/a> and download it on your computer.<\/p>\n\n\n\n<p>If you use\u00a0<a href=\"https:\/\/packagist.org\/\">Packagist<\/a>\u00a0for installing packages, then update your\u00a0<code>composer.json<\/code>\u00a0file as mentioned below:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;application\/json&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JSON&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;json&quot;}\">{\n    &quot;require&quot;: {\n        &quot;scssphp\/scssphp&quot;: &quot;^1.10.3&quot;\n    }\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Command Line Tool<\/h2>\n\n\n\n<p>A really basic command line tool is included for integration with scripts. It is called&nbsp;<code>pscss<\/code>. It reads SCSS from either a named input file or standard in, and returns the CSS to standard out.<\/p>\n\n\n\n<p>Usage:\u00a0<code>bin\/pscss [options] [input-file] [output-file]<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Available Options<\/h2>\n\n\n\n<p>If passed the flag&nbsp;<code>-h<\/code>&nbsp;(or&nbsp;<code>--help<\/code>), input is ignored and a summary of the command\u2019s usage is returned.<\/p>\n\n\n\n<p>If passed the flag&nbsp;<code>-v<\/code>&nbsp;(or&nbsp;<code>--version<\/code>), input is ignored and the current version is returned.<\/p>\n\n\n\n<p>The flag\u00a0<code>-s<\/code>\u00a0(or\u00a0<code>--style<\/code>) can be used to set the\u00a0<a href=\"https:\/\/scssphp.github.io\/scssphp\/docs\/#output-formatting\">output style<\/a>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;HTML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;html&quot;}\">&lt;span class=&quot;nv&quot;&gt;$ &lt;\/span&gt;bin\/pscss &lt;span class=&quot;nt&quot;&gt;-s&lt;\/span&gt; compressed styles.scss<\/pre><\/div>\n\n\n\n<p>The flag\u00a0<code>-I<\/code>\u00a0(or\u00a0<code>--load_path<\/code>) 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SCSSPHP Library Reference<\/h2>\n\n\n\n<p>To use the scssphp library either require\u00a0<code>scss.inc.php<\/code>\u00a0or use your\u00a0<code>composer<\/code>\u00a0generated auto-loader, and then invoke the\u00a0<code>\\ScssPhp\\ScssPhp\\Compiler<\/code>\u00a0class:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">require_once &quot;scssphp\/scss.inc.php&quot;;\n\nuse ScssPhp\\ScssPhp\\Compiler;\n\n$compiler = new Compiler();\n\necho $compiler-&gt;compileString('\n  $color: #abc;\n  div { color: lighten($color, 20%); }\n')-&gt;getCss();<\/pre><\/div>\n\n\n\n<p>The\u00a0<code>compileString<\/code>\u00a0method takes the\u00a0<code>SCSS<\/code>\u00a0source code as a string and an optional path of the input file (to resolve relative imports), and returns a\u00a0<code>CompilationResult<\/code>\u00a0value object containing the CSS and some additional data. If there is an error when compiling, a\u00a0<code>\\ScssPhp\\ScssPhp\\Exception\\SassException<\/code>\u00a0is thrown with an appropriate message.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>scssphp\u00a0is a free and open source compiler for\u00a0SCSS\u00a0that is written using PHP programming language. Basically, SCSS is a CSS preprocessor language that gives us additional features like variables, functions, mixins, imports, control directives, nesting, and color manipulation. You can easily use scssphp\u00a0in any existing or new PHP-based project. It is packed with a command line &#8230; <a title=\"PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library\" class=\"read-more\" href=\"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/\" aria-label=\"Read more about PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":1762,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-2730","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library<\/title>\n<meta name=\"description\" content=\"scssphp\u00a0is a free and open source compiler for\u00a0SCSS\u00a0that is written using PHP programming language. Basically, SCSS is a CSS preprocessor language that\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library\" \/>\n<meta property=\"og:description\" content=\"scssphp\u00a0is a free and open source compiler for\u00a0SCSS\u00a0that is written using PHP programming language. Basically, SCSS is a CSS preprocessor language that\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-09T16:19:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-09T16:19:43+00:00\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library","description":"scssphp\u00a0is a free and open source compiler for\u00a0SCSS\u00a0that is written using PHP programming language. Basically, SCSS is a CSS preprocessor language that","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/","og_locale":"en_US","og_type":"article","og_title":"PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library","og_description":"scssphp\u00a0is a free and open source compiler for\u00a0SCSS\u00a0that is written using PHP programming language. Basically, SCSS is a CSS preprocessor language that","og_url":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-08-09T16:19:41+00:00","article_modified_time":"2022-08-09T16:19:43+00:00","author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library","datePublished":"2022-08-09T16:19:41+00:00","dateModified":"2022-08-09T16:19:43+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/"},"wordCount":309,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/","url":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/","name":"PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","datePublished":"2022-08-09T16:19:41+00:00","dateModified":"2022-08-09T16:19:43+00:00","description":"scssphp\u00a0is a free and open source compiler for\u00a0SCSS\u00a0that is written using PHP programming language. Basically, SCSS is a CSS preprocessor language that","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","width":880,"height":495,"caption":"Default Featured Image"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/php7-compile-scss-to-css-code-in-command-line-using-scssphp-library\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=2730"}],"version-history":[{"count":0,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2730\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/1762"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=2730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=2730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=2730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}