08.
Sourcemaps only in Development
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
6 Comments
Hi Ryan,
First of all - a big thank you for all tutorials and especially this one, it is helping me a lot!
I'm trying to create a file _variables.scss which should hold all the global colors, mixins and stuff like this. What is the right approach of using these variables into the layout.scss file without gulp throwing the below error
Error: app/Resources/assets/sass/layout.scss
Error: Undefined variable: "$primary-color".
I have googled a bit and found that I should do:
@import "variables" into the layout.scss
but it seems(to me) that this is the lame way of using variables is SCSS so could you please let me know if there is any other way of using variables like the above described way?
Wish you a nice day ahead!
Hey Nikolay,
Glad this tutorial is useful for you! So if you have a file with all declared variables, and you want to use them in another SCSS file - yes, you have to import it there *before* start using those variables, otherwise it's not clear where those variables are declared for the process that parses your SCSS content. So, importing files in SCSS files is totally OK.
Cheers!
Hi Victor,
Thank you very much for the answer! Could you please let me know if I'm on the right way here. I have the below folder structure
into styles.scss I have the following:
@import "variables-site/variables-site";
@import "layout";
and again I get this error:
Error: Undefined variable: "$primary-color".
EDIT (03-12.2018): really sorry for the spam but I have found where is the issue with my code and folder structure. The idea is to have folders for each structure element like layout, mixins, variables, etc... and then into the styles.scss to have each of these imported. This way the gulp file will compile only the styles.scss file in the correct order and will not touch the folders.
Hope this would help in any way the other subscribers :)
Hey Niki,
Don't worry about spamming us with questions ;) I'm glad you found the solution!
Cheers!
If I want to use bootstrap mixins in my stylesheet (css is now a scss) by importing bootstrap.scss eg
@import "../../../../vendor/bower_components/bootstrap-sass/assets/stylesheets/bootstrap";
I get all sorts of errors (below). (intellij)
Q1: Why cant I import "/vendor/bower_components.." ? It says file not found. Is there someway to configure the "root" for imports?
Q2: what is the correct approach to making my style.css a style.scss which imports bootstrap.scss? Do I need to copy (recursively the bootstrap-sass files)? If so how to do this recursively? This is not recursive. How to modify the app.copy function?
app.copy (
config.bowerDir+'/bootstrap-sass/assets/stylesheets/*',
'app/Resources/assets/sass'
);
This might be a bit confusing but I suspect my confused ramblings might be understood by your experienced self!
errors involvoing sourcemaps when using a scss file which import bootstrap.scss:
/home/rgr/development/gitprojects/vollfilm-new/node_modules/source-map/lib/source-map-generator.js:277
throw new Error('Invalid mapping: ' + JSON.stringify({
^
Error: Invalid mapping: {"generated":{"line":10903,"column":17},"source":"../../../../vendor/bower_components/bootstrap-sass/assets/stylesheets/bootstrap/mixins/_clearfix.scss","original":{"line":14,"column":-13},"name":null}
at SourceMapGenerator_validateMapping [as _validateMapping] (/home/rgr/development/gitprojects/vollfilm-new/node_modules/source-map/lib/source-map-generator.js:277:13)
at SourceMapGenerator_addMapping [as addMapping] (/home/rgr/development/gitprojects/vollfilm-new/node_modules/source-map/lib/source-map-generator.js:101:12)
at /home/rgr/development/gitprojects/vollfilm-new/node_modules/concat-with-sourcemaps/index.js:60:28
at Array.forEach (native)
at SourceMapConsumer_eachMapping [as eachMapping] (/home/rgr/development/gitprojects/vollfilm-new/node_modules/source-map/lib/source-map-consumer.js:155:14)
at Concat.add (/home/rgr/development/gitprojects/vollfilm-new/node_modules/concat-with-sourcemaps/index.js:58:18)
at DestroyableTransform.bufferContents [as _transform] (/home/rgr/development/gitprojects/vollfilm-new/node_modules/gulp-concat/index.js:68:12)
at DestroyableTransform.Transform._read (/home/rgr/development/gitprojects/vollfilm-new/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)
at DestroyableTransform.Transform._write (/home/rgr/development/gitprojects/vollfilm-new/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83)
at doWrite (/home/rgr/development/gitprojects/vollfilm-new/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:338:64)
r
Hi Richie Hamburg!
Sorry for my slow reply! And I'm afraid you give me too much credit - this is a tough one! I have not experienced this issue before, but it looks like you're not alone: https://discourse.roots.io/... and https://github.com/sass/nod.... Unfortunately, it doesn't look like there's a "for sure" workaround :/. You could of course compile your Bootstrap SASS into CSS and then include the bootstrap CSS in your gulpfile, but it's kind of a bummer.
Here on KnpU, we've actually migrated to webpack, which we're very happy with. Unfortunately, our tutorial on it - http://knpuniversity.com/sc... - hasn't been released yet. There's also a tool that will come out pretty soon to make webpack easier to work with. I know, that's not that helpful - it's a lot of "we use webpack, but things that make it easier aren't ready yet". But soon!
Cheers!
"Houston: no signs of life"
Start the conversation!