Compile Sass

Sass makes CSS more dynamic, but the compile setup can feel like a burden. You don't need a bundler for it: npm scripts and the official Sass command-line interface are enough.

1. Install Node.js

npm comes with Node.js. Download the installer for your system, or use a package manager like Homebrew, Chocolatey or fnm. Spruce CSS's tooling uses the current LTS version.

2. Initialize the Project

Open your terminal in the project folder and create a package.json file:

npm init -y

3. Install Sass and Spruce CSS

npm install sass --save-dev
npm install sprucecss

Use Dart Sass (the sass package). LibSass and Node Sass are deprecated and don't support the module system Spruce is built on.

4. Add the Compile Scripts

Add two scripts to the scripts object of your package.json:

{
  "scripts": {
    "sass:dev": "sass --watch --update --style=expanded --load-path=node_modules assets/scss:assets/css",
    "sass:prod": "sass --no-source-map --style=compressed --load-path=node_modules assets/scss:assets/css"
  }
}
  • sass:dev is for development: readable output, source maps, and a watcher that recompiles on every change.
  • sass:prod is for production: compressed output, no source map, runs once.
  • --load-path=node_modules lets you write @use 'sprucecss/scss/spruce' without a relative path. With Sass 1.71+ you can also use --pkg-importer=node and @use 'pkg:sprucecss'.

What is a source map? A file that lets the browser map the compiled CSS back to your source files, so the developer tools show the original file names and lines.

5. Structure the Files

my-project/
├── assets/
│   ├── css/
│   │   └── main.css        // compiled
│   └── scss/
│       ├── config/
│       │   └── _config.scss
│       ├── component/
│       │   └── _card.scss
│       └── main.scss       // entry point
├── node_modules/
└── package.json

Sass compiles every file that doesn't start with an underscore (_); the partials are only included through @use and @forward. The next guide, Configure Your Project, shows what goes into these files.

6. Run the Scripts

npm run sass:dev
npm run sass:prod

Going Further

Documentation

Learn about Spruce CSS through our extensive documentation.

Components

Explore our UI library of accessible components built with Spruce CSS.

Blocks and Pages

Full-width page blocks and complete page templates, ready to copy.

Find us on GitHub

Did you find a bug? Have an idea or a question? Please open an issue to help us develop the project.