I'm trying to migrate my css over to scss for a PHP application, but I'm confused about the proper workflow for generating css files. I'm using scssphp, which is a compiler for scss written in PHP.
In all my pages, I use the following stylesheet: css/mycss.css
. I've put the scss
version of the stylesheet in css/scss/mycss.scss
. When I make changes to the scss file, I compile it locally by entering into my browser:
localhost/mywebsite/style.php/mycss.scss
The style.php
file is as follows:
require "vendor/leafo/scssphp/scss.inc.php";
$scss = new scssc();
$directory = "css/scss";
$server = new scss_server($directory,null,$scss);
$server->serve();
This compiles the scss file and writes it to the css/scss/scss_cache
folder. The filename is some hash. Here is my resulting directory structure:
style.php
-css
mycss.css
-scss
mycss.scss
-scss_cache
4edf7f7bf9238jdsk9281sjkj32.css
Now ideally, I would like for the compiler to overwrite the css/mycss.css
file. Is there a way to do this, or what's a proper workflow for replacing the original css file with the newly compiled css? I could always just copy and paste every time, but that doesn't seem very efficient.
scssphp
is meant to be used to serve the stylesheets directly. But if you'd like to just use the compiler functionality, you can do that:
require "vendor/leafo/scssphp/scss.inc.php";
$scss = new scssc();
$scssIn = file_get_contents(__DIR__ . '/css/scss/mycss.scss');
$cssOut = $scss->compile($scssIn);
file_put_contents(__DIR__ . '/css/mycss.css', $cssOut);
See http://leafo.net/scssphp/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With