Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does an underscore at the start of an *.scss file name indicate?

Tags:

sass

I've had a look into CSS setups for a couple of projects that other people developed and I can understand most of what's going on.

The programmers have, however, created some files whose names start with the underscore (for example: _variables.scss). I have seen files named like this in both of the projects.

I can't figure out what this convention represents. Is there a special reason why the people are naming the files this way?

like image 771
MariaZ Avatar asked Jun 14 '15 05:06

MariaZ


People also ask

What does an underscore in a file name mean?

Removing the space or underscore reduces the length of the file name but by using capital letters to differentiate between the words, the file name is still readily recognisable.

Why do SCSS files start with _?

The _ (underscore) is a partial for scss. That means the stylesheet its going to be imported (@import) to a main stylesheet i.e. styles. scss. The advantage on using partials is that you can use many files to organize your code and everything will be compiled on a single file.

Are underscores allowed in file names?

Illegal Filename Characters Don't start or end your filename with a space, period, hyphen, or underline. Keep your filenames to a reasonable length and be sure they are under 31 characters. Most operating systems are case sensitive; always use lowercase. Avoid using spaces and underscores; use a hyphen instead.

How do I name a Sass file?

Naming Conventions. General rules for naming conventions apply to variables, functions, and mixins. When naming anything in Sass it's recommended to use all lowercase letters with dashes for separation. Sass code syntax is actually based on the CSS guidelines ruleset.


2 Answers

The only reason I can find to use underscore before the name of the partial is what's described in the Sass docs here:

The underscore lets Sass know that the file is only a partial file and that it should not be generated into a CSS file.

Any SASS files not beginning with an underscore will be rendered on their own, which will fail if they are using variables or mixins defined elsewhere.

In the end I have concluded that the underscore is just used to clarify that it is a partial file. We can also use a partial file without using an underscore as prefix.

like image 50
Pardeep Jain Avatar answered Oct 19 '22 07:10

Pardeep Jain


Sometimes that naming convention is used for templates or template part files, you could find this being used in MVC frameworks.

In other places this might mean that this variable or file is private and can only be accessed by the server or the running program. It all depends on the language you're programming really, but this is simply a naming convention.

like image 1
odedta Avatar answered Oct 19 '22 05:10

odedta