Skip to content

Instantly share code, notes, and snippets.

@rveitch
Last active May 11, 2024 19:52
Show Gist options
  • Save rveitch/84cea9650092119527bc to your computer and use it in GitHub Desktop.
Save rveitch/84cea9650092119527bc to your computer and use it in GitHub Desktop.
Sass 7-1 Pattern
sass/
|
|– base/
| |– _reset.scss # Reset/normalize
| |– _typography.scss # Typography rules
| ... # Etc…
|
|– components/
| |– _buttons.scss # Buttons
| |– _carousel.scss # Carousel
| |– _cover.scss # Cover
| |– _dropdown.scss # Dropdown
| ... # Etc…
|
|– layout/
| |– _navigation.scss # Navigation
| |– _grid.scss # Grid system
| |– _header.scss # Header
| |– _footer.scss # Footer
| |– _sidebar.scss # Sidebar
| |– _forms.scss # Forms
| ... # Etc…
|
|– pages/
| |– _home.scss # Home specific styles
| |– _contact.scss # Contact specific styles
| ... # Etc…
|
|– themes/
| |– _theme.scss # Default theme
| |– _admin.scss # Admin theme
| ... # Etc…
|
|– utils/
| |– _variables.scss # Sass Variables
| |– _functions.scss # Sass Functions
| |– _mixins.scss # Sass Mixins
| |– _helpers.scss # Class & placeholders helpers
|
|– vendors/
| |– _bootstrap.scss # Bootstrap
| |– _jquery-ui.scss # jQuery UI
| ... # Etc…
|
|
`– main.scss # Main Sass file
@HowdyMcGee
Copy link

HowdyMcGee commented Aug 16, 2020

I like this idea, but the Sass docs suggest moving away from @import and toward @use. Finding practical organizational guidelines using @use and @forward seems complicated. A good read nonetheless.

@samayo
Copy link

samayo commented Aug 22, 2020

I like the idea of this but the Sass docs suggest moving away from @import and toward @use. Find practical organizational guidelines using @use and @forward seems to be difficult. Good read none-the-less.

fyi: nonetheless is one word

@jochri3
Copy link

jochri3 commented Jan 5, 2021

Source: http://sass-guidelin.es/#the-7-1-pattern

I think that utils is the equivalent abstract

@enginW
Copy link

enginW commented Jan 22, 2021

thank you, this is great i will use

@pedrocardoz0
Copy link

Thanks, that's perfect!

@Meilline
Copy link

Thanks a lot !

@saini-g
Copy link

saini-g commented Jun 1, 2021

My SCSS 7-1 architecture

Here's the setup that I'm currently using for a project. Ignore the custom-partials folder, it is not part of the 7-1, I use it for writing temporary stuff which in most cases will eventually be moved to one of the other folders

This is implemented using the new @forward and @use module system, each folder contains an _index.scss file used to forward the refs to individual files in that folder. Below is the _index.scss file for the components folder, the other folders' index files are similar

@forward './checkbox-toggle';
@forward './flex-text';

CC: @carolyn01 , @HowdyMcGee hope this helps

@stebenwolf
Copy link

Create a file called script.sh in your ./sass folder and paste this code.

mkdir abstract pages layout base components 
cd abstract
touch _function.scss _mixins.scss _variables.scss
cd .. 
cd base 
touch _animations.scss _typography.scss _utilities.scss _base.scss
# This is a comment
# Use below imports in your main inde.scss file
# @import "./abstract/variables";
# @import "./layout/header";
# @import "./base/animations";
# @import "./base/typography";
# @import "./components/button";

Navigate to ./sass folder and double click on this file (script.sh)
It will automatically create some of the folder and files for you. 😁
I'll update this script as I create more files for myself 😛

Thanks for the code @abhagsain

For those interested I made a similar batch version

  1. Open your favourite text editor
  2. Paste the code below
  3. Save it as .bat
  4. Copy/paste it and launch it wherever you need to
@ECHO OFF 
:: This batch file creates all necessary files for SASS
:: Inspired by @abhagsain https://gist.github.com/abhagsain 
:: https://gist.github.com/rveitch/84cea9650092119527bc#gistcomment-3040049

TITLE SASS Automatic Setup

ECHO ==========================
ECHO SASS AUTOMATIC SETUP
ECHO ============================
ECHO/
ECHO This program automatically creates all the files and folders you need for your SASS project.
ECHO/
PAUSE
ECHO Please wait... Creating files and folders

ECHO/
:: SASS Folder
ECHO Creating SASS folder...
if exist sass\NUL echo - SASS folder already exists
if not exist sass\NUL (
    mkdir sass
    echo + SASS folder creation: done.
)

ECHO/
ECHO Moving to SASS folder
cd sass
ECHO Creating SASS Subfolders...

ECHO/
:: Abstract folder
if exist abstract echo - abstract folder already exists
if not exist abstract (
    mkdir abstract
    echo + Abstract folder creation: Done.
)
:: Pages folder
if exist pages echo - pages folder already exists
if not exist pages (
    mkdir pages
    echo + Pages folder creation: Done.
)
:: Layout folder
if exist layout echo - layout folder already exists
if not exist layout (
    mkdir layout
    echo + Layout folder creation: Done.
)
:: Base folder
if exist base echo - base folder already exists
if not exist base (
    mkdir base
    echo + Base folder creation: Done.
)
:: Components folder
if exist components echo - components folder already exists
if not exist components (
    mkdir components
    echo + Components folder creation: Done.
)

ECHO/
ECHO Moving to Abstract...
cd abstract
ECHO\
ECHO Creating Abstract files
ECHO -------------------
:: _function.scss
if exist _function.scss echo - _function.scss already exists
if not exist _function.scss (
    type nul >_function.scss
    ECHO + _function.scss created
)
:: _mixins.scss
if exist _mixins.scss echo - _mixins.scss already exists
if not exist _mixins.scss (
    type nul >_mixins.scss
    ECHO + _mixins.scss created
)
:: _variables.scss
if exist _variables.scss echo - _variables.scss already exists
if not exist _variables.scss (
    type nul >_variables.scss
    ECHO + _variables.scss created
)
ECHO -------------------

ECHO/
ECHO Moving to Base
cd ..
cd base

ECHO Creating base files
ECHO -------------------
if exist _animations.scss echo - _animations.scss already exists
if not exist _animations.scss (
    type nul >_animations.scss
    ECHO + _animations.scss created
)
if exist _typography.scss echo - _typography.scss already exists
if not exist _typography.scss (
    type nul >_typography.scss
    ECHO + _typography.scss created
)
if exist _utilities.scss echo - _utilities.scss already exists
if not exist _utilities.scss (
    type nul >_utilities.scss
    ECHO + _utilities.scss created
)
if exist _base.scss echo - _base.scss already exists
if not exist _base.scss (
    type nul >_base.scss
    ECHO + _base.scss created
)
ECHO -------------------

ECHO/
ECHO You're all set up! Enjoy
ECHO/
ECHO Psst... Before you go :
ECHO Use below imports in your main inde.scss file :
ECHO/
ECHO    @import "./abstract/variables";
ECHO    @import "./layout/header";
ECHO    @import "./base/animations";
ECHO    @import "./base/typography";
ECHO    @import "./components/button";
PAUSE

@Tomerozfresko
Copy link

@saini-g Thank you very much.
However, are you familiar with variables using this format?
Some variables are globally usable and some are not, even if declared in same *_.scss file.

@lucasfernandezdev
Copy link

Hi, thanks for this. But I have a problem. I use bootstrap with npm, how should I setup this? I'm a bit lost :( (New)

@tjcchen
Copy link

tjcchen commented Sep 18, 2022

Thanks a lot! Very helpful.

@Tsu3xyz
Copy link

Tsu3xyz commented Dec 15, 2022

Love it ::D

@Mobin-Karam
Copy link

I Love it, Thanks man. :)

@Mobin-Karam
Copy link

Create a file called script.sh in your ./sass folder and paste this code.

mkdir abstract pages layout base components 
cd abstract
touch _function.scss _mixins.scss _variables.scss
cd .. 
cd base 
touch _animations.scss _typography.scss _utilities.scss _base.scss
# This is a comment
# Use below imports in your main inde.scss file
# @import "./abstract/variables";
# @import "./layout/header";
# @import "./base/animations";
# @import "./base/typography";
# @import "./components/button";

Navigate to ./sass folder and double click on this file (script.sh) It will automatically create some of the folder and files for you. 😁 I'll update this script as I create more files for myself 😛

man thank a lot for your help :)

@DevRufet
Copy link

thanks,very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment