avian
avian

Reputation: 1753

How to convert directory SASS/SCSS to CSS via command line?

I tried:

sass-convert --from scss --to css --recursive app/assets/stylesheets temp

But this only converts css to SASS, and I want the other way around.

Then I looked at the sass command, but it doesn't look like I can pass it a directory.

Upvotes: 48

Views: 100395

Answers (6)

wly185
wly185

Reputation: 139

https://sass-lang.com/guide

enter image description here

you can use

sass --watch [input folder path]:[output folder path]

i tried running it in a new terminal and after that sass watches the folder and compiles upon any changes.

Upvotes: 1

Seyed Kazem Mousavi
Seyed Kazem Mousavi

Reputation: 457

you can use this code

sass --watch file.sass:file.css

or

sass --watch folderSass:foldercss

if you want to create css.main you can use this code

sass --watch sass:css --style compressed

Upvotes: 0

Reggie Pinkham
Reggie Pinkham

Reputation: 12748

Use the sass command followed by the input file name and path, a colon (:) and the desired output file name and path. If the output file does not already exist Sass will generate it. For example,

sass sass/main.scss:css/main.css

However, this is a one-off command that would require being run every time you want to generate a new CSS file. A simpler and handier method is to use Sass's built-in --watch flag. This watches for changes to your Sass file and automatically runs the compile command each time you save changes.

sass --watch sass/main.scss:css/main.css

If you have multiple Sass files within a directory you can watch for changes to any file within that directory:

sass --watch sass:css

Sass also has four CSS output styles available: nested, expanded, compact and compressed. These can be used thus:

sass --watch sass:css --style compressed

Refer to the Sass documentation for more.

Upvotes: 21

kourouma_coder
kourouma_coder

Reputation: 1098

to that, simply go your project directory and do this :

sass --update sass-dir:assets/css

with sass-dir the directory containing your actual sass files and assets/css the desired output directory.

Hope this could help.

Upvotes: 12

KatieK
KatieK

Reputation: 13863

To do a one-time Sass compile instead of a watch, you can do this from the command line:

sass --update scss:css

To have Sass import one file (usually a partial, with a _ starting the filename), you can do this inside a Sass file:

@import "_base.scss";

This way, Sass knows where you want the include to occur.

By default, Sass can't import an entire directory. The Sass Globbing gem, however, can. You can install it from the command line:

gem install sass-globbing

And then watch with it:

sass -r sass-globbing --watch sass_dir:css_dir

Note that globbing will import files alphabetically, so be sure your CSS will cascade appropriately if this occurs.

Upvotes: 67

kenorb
kenorb

Reputation: 166871

You can use compass to convert Sass files into CSS.

To initialize the config.rb, try:

compass init --syntax=sass --css-dir=css --javascripts-dir=js

Once you've the configuration file, try:

compass compile

or by specifying the file explicitly: compass compile sass/foo.scss.


To install it, try:

sudo gem update
sudo gem install sass compass

Upvotes: 2

Related Questions