How to import a scss file into a compass only if it exists?

I need to have a special scss file that is different for each project installation, so I don't want to include it in the git archive. But everything should work, even if this file does not exist.

Is there a way for the @import scss file only if it exists ignoring the file error not found?

+5
source share
2 answers

To do this, you need to use the "import path" option, where the path you import contains the backup files that you want to import (in our case, we need an empty file).

Option 1: Vanilla Sass

File structure

├── fallback
    ├── _example.scss // <-- our blank file
├── _example.scss // <-- the file for the user to customize (optional)
├── style.scss

In style.scss:

@import "example";
/* the rest of our styles */

When you run the sass command, you should write it like this:

sass --watch ./css:./sass --load-path ./sass/fallback

, sass, , .

. : SCSS ?

2:

, Compass , . . : http://compass-style.org/help/tutorials/extensions/

+5

, sass-globbing, .

:

stackoverflow-14975341/
├── .gitignore
├── config.rb
├── css/
│   └── screen.css
└── sass/
    ├── optionals/
    │   ├── .gitkeep
    │   ├── _01_style.scss
    │   └── _03_style.scss
    └── screen.scss

:

# config.rb
require 'sass-globbing'

sass_dir   = 'sass'
css_dir    = 'css'
relative_assets = true

// sass/screen.scss
@import "optionals/*";

// sass/optionals/_01_style.scss
.optional1 {
  background-color: red;
}

// sass/optionals/_03_style.scss
.optional3 {
  background-color: green;
}

.gitignore:

sass/optional/*

, optional, .gitkeep ( ).

, Compass screen.css, _02_style.scss .

// css/screen.css
/* line 1, ../sass/optionals/_01_style.scss */
.optional1 {
  background-color: red;
}

/* line 1, ../sass/optionals/_03_style.scss */
.optional3 {
  background-color: green;
}

, .

+2

All Articles