I have a workflow setup where I have all the config scss
files housed under one folder. I then have a _styles.scss
file where I'm importing
all of these files.
Now, in another file, hero.scss
, I'm referencing variables which are in those config files. But I get undefined errors.
I had a look further and found this other question from Stack Overflow, seems like the best answer is suggesting the same approach I have adopted, but it's not working for me?
Folder structure:
theme
- assets
- sass
- config
- _variables.scss
- _styles.scss
- modules
- hero
- hero.html
- hero.scss
_variables.scss
$white: #FFF;
$black: #000;
`_styles.scss'
@import "../../../node_modules/bootstrap/scss/bootstrap.scss";
@import "../../../node_modules/bootstrap/scss/variables.scss";
@import "../../../node_modules/bootstrap/scss/mixins.scss";
@import "config/variables.scss";
hero.scss
.hero{
color: $white;
}
None of the imports work, because when trying to use the Bootstrap mixins i.e.
.hero{
@include media-breakpoint-up(sm){
color: $white;
}
}
They don't work either, even though I've @imported them too. Edit:
If I do the following in hero.scss
@import "../../assets/sass/styles.scss";
.hero{
background: $white;
}
Whilst the vars will now be recognised, when running gulp, all the styles from the files imported in styles/scss
, they'll now be compiled alongside my module code.
For example:
My gulpfile.js
for reference:
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('autoprefixer');
var postcss = require('gulp-postcss');
var paths = {
styles: {
src: 'modules/**/*.scss',
dest: 'modules'
}
}
function scss() {
return gulp.src(paths.styles.src)
.pipe(sass().on('error', sass.logError))
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest(paths.styles.dest));
}
exports.scss = scss
function watch() {
scss();
gulp.watch(paths.styles.src, scss);
}
exports.watch = watch
What the above is essentially doing is compiling scss
files found in subfolders of the parent folder modules
.
With this @import "../../assets/sass/styles.scss";
now added to hero.scss
(which is housed under modules), it's now adding my config code to that modules css file.
Complete folder structure:
theme
- assets
- sass
- config
- _variables.scss
- _client-styles.scss
- styles.scss
- modules
- hero
- hero.html
- hero.scss
- hero.css (running gulp will compile this)
So hero.css
, with the import is now contains code from hero.scss
and client-styles.scss
for example. Whereas I only need it to compile the sass from hero.scss
.