Tuesday, May 7, 2024
HomeCSSHalf 3: Constructing Our Sass Structure

Half 3: Constructing Our Sass Structure


Sass logo on a pink gradient background

Within the earlier two articles we went by configuring a venture starter repository utilizing NPM scripts and Parcel. I are likely to make use of kind of the identical Sass structure for each venture, so I would like my boilerplate to incorporate the SCSS information and folders I have to get began writing code right away. That is my most popular structure, loosely primarily based on Harry Roberts’ ITCSS (Inverted Triangle CSS), and our boilerplate at my earlier company, Mud:

  1. Config This usually accommodates three information: It’s the place I outline all of the Sass variables, mixins and performance to be used all through the venture. I typically use a single file for my variables, protecting breakpoints, colors, spacing and anything. However there’s no purpose the variables file couldn’t be damaged up into a number of information, which is likely to be a good suggestion for giant initiatives.

  2. Base Just about all the things in right here includes writing types on factor selectors, fairly than courses. It consists of any resets (e.g. * { box-sizing: border-box; }), and base types for typography and type components, a few of which can be over-ridden on the element stage in a while.

  3. Objects Any small, reusable items of UI, which may seem in a number of parts, belong right here. I begin with a buttons.scss file as a result of, properly, just about each venture has buttons! However I solely have a tendency so as to add others once I want them.

  4. Globals I prefer to preserve any parts that shall be used on each web page, such because the header and footer, in a separate folder from the remainder of the parts. I additionally add generic structure courses in right here – if I’ve a grid that I wish to use in a number of locations, for instance. I want to make use of courses fairly than mixins for these, because it’s one fewer stage of abstraction.

  5. Parts That is for the bigger chunks of UI, corresponding to hero sections, playing cards, media objects and extra. It’s the place the majority of my CSS shall be written, however I depart it empty to start with in order that I can add particular person element information as and once I want them.

  6. Utilities That is for single-purpose, reuseable atomic (or utility) courses that could possibly be utilized to any factor. E.g. The next could possibly be used to set vertical padding on all components which have this class utilized:

.padding-v {
padding-top: var(--pad);
padding-bottom: var(--pad);
}

I have a tendency to not use too many of those, so I’m going to go away this file empty till I would like it.

So, to complete off our venture starter, I’m going so as to add the next file construction to the src/scss listing:

01-config
	_variables.scss
	_functions.scss
	_mixins.scss
02-base
	_resets.scss
	_typography.scss
	_forms.scss
03-objects
	_buttons.scss
04-globals
	_header.scss
	_footer.scss
	_layout.scss
05-components
06-utilities

You would possibly discover every folder has a numerical prefix – that is in order that when considered within the file system the visible order will mirror the import order. This may make it a lot faster and simpler to seek out the file I would like, and can assist keep away from any confusion.

It’s doubtless you’ll have your individual most popular Sass structure, so I might advocate including not less than a fundamental folder construction to your boilerplate – or be at liberty to tweak this one. Even if you happen to use an atomic CSS framework (like Tailwind), the probabilities are you would possibly want to put in writing some CSS your self, so having the structure in place is smart.

Conclusion

This concludes the mini-series on A Fashionable Entrance-end Workflow. We’ve learnt about putting in NPM packages, writing scripts to run duties, utilizing Parcel for simpler automation, and including a fundamental Sass structure. This starter repository consists of all the things we lined. Be happy to clone it or fork it – and add to it – to your personal initiatives.

See different articles on this collection

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments