Sass Fundamentals

Preprocesser Benefits

Sass Fundamentals

Check out a free preview of the full Sass Fundamentals course

The "Preprocesser Benefits" Lesson is part of the full, Sass Fundamentals course featured in this preview video. Here's what you'd learn in this lesson:

From keeping styles organized and variables, Mike discusses the benefits of using a preprocessor like Sass. A preprocessor is a program that processes its input data to produce output that is used as input to another program.


Transcript from the "Preprocesser Benefits" Lesson

>> Mike: With that let's go into talking about preprocessors. What is a preprocessor? Well, Sass is one of them. These are things that, are tools that allow us to define something that defines similar concepts to CSS. But what we're writing is not CSS. It's often sort of an abstraction of it.

Something that gives us some things that CSS is missing. And three popular examples here are Less, Sass and stylist. All of these compile to CSS meaning you put them through a tool of some sort and they will return something a brother can understand. Often times these things are like, you'll run a command and you'll say, here's my input file, here's where I would like you to put my output file, and you will get CSS coming out.

So, these all involve variables, these all involve the ability to compose rules together. Meaning you can define something in one place and then bring that style into two different other styles or multiple other styles. You can define things like mix ins, which we'll get into later, they're almost like functions that return CSS if that makes sense.

And because these are relatively simple in terms of developer tooling, it's just sort of one file in one file out. Often times they're pretty easy to setup in that, in comparison to other things, right? It's often like a ten minute job or less to get Sass or Less or Stylus working with your project.

So why would we want to use one? And I'd like to sort of reword this a little on the fly and say, why would we wanna use this always? Why would you wanna reach for using a preprocessor, even for the smallest project that you have to tackle? Well first, it gives us stuff that should have been in CSS in the first place.

The idea of having a variable is pretty important right, because we often times we are repeating things like colors and paddings all over the place. You end up having to almost get like a pocket calculator out in order to define what should this margin be? Because I've got a side bar that's this width, and then some padding on the side of it, and all of that, all of those expressions, those should be built into the way we define our styles.

They should not be things that we have to do as developers in our brains.
>> Mike: You will find that it's easier to maintain your styles. It is harder to make subtle mistakes, right? Like misspellings and highly repetitive CSS are very, very common. It's easier to keep your styles organized.

So I heard some people in the room, they use Angular 2 or other component based libraries, like Ember. You want to kind of say, these are the styles that are defined for this component, and they exist in one file and they don't overlap or interact with styles for other components.

So we get the ability to kind of break our code up, in a way that makes sense to us as developers, without imposing a cost on our users enforcing them to download a whole bunch of files. And as I said, it's really easy to set this up and oftentimes we even get libraries like sets of mixens and variables that already come, set up for Sass or for Less.

So Bootstrap's a great example. Bootstrap 3, it used Less. Bootstrap 4 uses Sass. And the idea here is you could bring this in as a dependency and customize some of the variables that define what Bootstrap looks like. Rather than superseding the Bootstrap CSS that you bring in, and overriding it you can sort of tune it so that it's the way you want it to look in the first place, which is a lot cleaner, it results in a lot less code being sent over to your users.

Just better and easier to maintain overall. So, lots of good options for using pre-processors. Today we're going to be focusing entirely on Sass.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now