Reputation: 998
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.
Upvotes: 6
Views: 6716
Reputation: 1792
You would have to replace css/mycss.css
with mywebsite/style.php/mycss.scss
in all your pages.
<link rel="stylesheet" href="/mywebsite/style.php/mycss.scss">
scssphp will now try to read mycss.css from its cache or compile it.
but I don't think that's be best way to work with scss. I recommend using one of the official sass programms or event grunt to automate things.
Upvotes: 3
Reputation: 2557
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/.
Upvotes: 13