sass --watch is not watching partials - macos

I seem not to be able to make sass watch changes in my partials, so it is only when I make changes to my main scss file that the css file is compiled.
I have a folder with my m.scss and m.css file and a subfolder to that called partials with my partials in. So:
m.css
m.scss
partials/_base.scss
I have tried:
sass -I partials --watch m.scss:m.css
But does not work.
I am on a mac with an ubuntu server running on paralels and running Haml/Sass 3.0.15 (Classy Cassidy)

The simple way I got this to work was to go to just do a watch on the folder with my primary css in. So if your css folder is call "css" then:
sass --watch css
That compiles m.scss into m.css everytime a scss file in the folder or a subfolder is changed

Related

How to use scss files in Laravel

I have downloaded a free HTML theme.
If I open index.html file of the theme in the browser it works perfectly.
However, now I need to integrate this theme in my Laravel Application. If I inspect element in the index.html file loaded in the browser, I can see that some .scss files are getting called.
The scss folder is present in the theme folder but I really don't know how to include this into my project
You can think of SASS as high level css which provides you with more features like making variable and easier css syntax etc ... but since browsers doesn't understands SASS you have to compile SASS into CSS there are multiple ways to do that.
First if your theme folder already has complied SASS (CSS Folder) you can use it if not and want to integrate with Laravel please follow these steps
Copy everything in your SASS Folder and place it in "/resources/assets/sass" so
they can be found by Laravel to be compiled
now you have to compile SASS into css you can use gulp manually or make use of
Laravel mix which is already implemented for you by Laravel
Laravel Ships with packages.json file you will find that in your app root
directory so before being able to compile SASS you have to run npm install in
your root directory (make sure that you have npm and node installed)
after running npm install now you can run either one of these to compile any
sass files you have in "resources/assets/sass"
npm run dev //this will compile one time only
npm run watch //this will automatically watch for any changes and compile
Now your sass files should have been compiled to css you can find the compiled css files in your "public/css" folder.
Hopefully you found this helpful you can read more about this in Laravel docs frontend section specifically Laravel Mix here
Laravel has a file called webpack.mix.js where you edit all frontend assets compilation by calling the mix.js/sass with the respective arguments. It is located at the root of the project.
1- In the resources folders create a new folder and call it scss with a app.scss file. The complete tree will be scss/app.scss
2- Go to the webpack.mix.js and add a new line: mix.sass('resources/sass/app.scss', 'public/css');. The first argument of the method is the source file, and the second is the destination folder.
3- In the app.scss file import all the theme scss files using #import 'file/source';
4- Open terminal/cmd in your Laravel project folder and Run npm run dev/watch to compiled your scss file, and at end your css file result will be located in public/css/app.css.
5- Import the app.css into your Html head section and reload the page. If the styles do not work, press ctrl + f5 to clean browser cache.
The latest version of Laravel utilizes a tool called Vite as a replacement for Laravel Mix.
In order to use Sass with Vite, make sure that Vite and Sass are installed run npm install and npm add -D sass
Make sure you have a sass or scss folder in your projects resources directory, and an scss file inside like app.scss
Make sure that you have configured vite.config.js (which can be found in a new Laravel projects root directory) to include an entry point for sass like so, utilizing the correct path and name for the folder you made:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/scss/app.scss', 'resources/js/app.js'],
refresh: true,
}),
],
});
And in your Blade files add the following, again making sure to use the correct path for the folder you made:
#vite(['resources/scss/app.scss', 'resources/js/app.js'])
Then you can build your sass using Vite by running npm run build

Compile multiple SASS files in multiple directories, into multiple CSS files in a separate, single directory

I need to compile multiple sass files in one directory into multiple corresponding css files in another directory. Eg:
src/folder1/file1.scss --compiles to-- public/file1.css
src/folder2/file2.scss --compiles to-- public/file2.css
Here is the command I am using:
./src/*/*.scss ./public
Prior to attempting this, I was compiling all .scss files in place using just ./src/*/*.scss, and was getting the corresponding .css files in their respective directories. Trying to dump these in a different directory, however, is not working. What is happening instead is that one of the .scss files imports a .scss partial an import statement into the .scss file itself, a .scss.map file is created, and nothing else happens after that.
Does SASS even have this capability? I've tried different variations of the above command and occasionally I'll see an error saying that 'public' is a directory, which leads me to believe SASS doesn't allow a directory as the output. In fact, the documentation only provides a single output file as the example for compiling SASS (i.e. sass input.scss output.css).
I'm using NPM scripts as a build tool so please no Grunt, Gulp, etc.
*One other thing to note. I just tried using sass --watch instead of the normal compile command, and it sort of does what I need it to:
sass --watch src:public
The only issue I'm having with this is that it does not create only css files in public. Instead it creates a folder and a .css and .css.map file in the folder. It seems SCSS will add a path for each .scss file respective to the relative path traversed by watch. This solution would be ideal if it would not create this extra folder.
You can compile multiple sass files into multiple css files by specifying multiple source:output separated by a space like this:
sass --watch src/file1.scss:dist/file1.css src/file2.scss:dist/file2.css
You can change the src or output paths as needed.
You have to tell the sass watch what file you want it to output, just like this:
sass --watch style.scss:style.css
You can even set it to output a compressed css file (the .map file happens automatically for each css):
sass --watch style.scss:style.css --style compressed
I usually go to one file, but theoretically you can watch different scss files and compile them to separate css files, not sure why you'd want to?, but it can be done.
For anything you want to group, import the related files to a scss file then compile it down to one file, then repeat these steps.
(Note: I'm running the sass gem for the above commands in Node.)

Why isn't my SASS watch command working?

Attempting on a Mac with the latest version of Yosemite
I'm using the latest version of sass to refactor my site. I'm setting up watch command via the command line. my directory setup has a scss folder with the main css stylesheet cloned as .scss. and no css folder.
When I attempt the sass --watch scss:css command while in the main project directory folder, I've been told that, if there isn't one present, a css folder should be generated and a cloned .css file should be created along with a map file. Command line tells me >>> Sass is watching for changes. Press Ctrl-C to stop. however, changes are not being recorded.
I've tried updating my gems and uninstalling/ reinstalling sass, but nothing seems to be working.
Just tried this - the css folder doesn't get autogenerated. You need to generate it yourself. From there on, you should be good to go.
So if you are in the main project folder with subfolders called scss and css and you have, for example, a main.scss file in the scss directory, you can run the command exactly as you specified and everything should work as specified.

How to configure a SCSS project?

I'm pretty new to SASS/SCSS and got a git project with CSS Files in the main directory which shall import partials from a subdirectory. I was wondering if it's possible to install sass on the server, create a compass project so that css files will be created automatically after a live edit of the scss files on the server? Or does it have to be local with a filewatcher? I already tried to set up a compass project on the server but no css files were created automatically. Was it because of wrong settings or is it just not possible this way?
If it's possible is there a good step by step tutorial? I already found this
Maybe the problem is the path. In my config.rb I changed the path without knowing what to write in the string if sass and css directory are the same as project path. Didn't work with "/" or an empty string.
Both Sass and Compass provide watch commands. You can use either:
sass --watch input.scss:output.css (options)
or, assuming you've got your Compass config file correctly setting your css_dir vairable:
compass watch
Either of those should recompile the css file upon changes. If you want this done live on the server, you'll need to execute the watch command on the server.
To add a point to #aerook's answer,
In your projects you may have multiple scss and css files. In which case you may use the following to watch the entire scss directory to make changes in the css directory
sass --watch scss:css
PS : scss and css are folder names in the same directory path.

how to compile scss files in my part folder?

I want to compile all the scss to css in my part folder . how to do it ?
the compass watch command can only compile the root sass folder to css folder.
for example: I want to compile top_menu.scss to top_menu.css.
config.rb
sass
css
part
top_menu
|--top_menu.php
|--sass
| |--top_menu.scss
|--css
| |--top_menu.css
Try this executing the compass watch command as it follows
compass watch --sass-dir part/top_menu/sass --css-dir part/top_menu/css -c config.rb
I hope it helps.
Cheers!
You should move the part folder inside the sass folder and set config.rb to watch the sass folder:
sass_dir = 'sass'
UPD1: if you want to keep the structure, try pointing sass_dir at the root folder. Another option is to make those files partials that would embed into one big css file instead of multiple smaller ones.

Resources