Sourcemap to original SCSS file
As i can see on your sass-loader
configuration, you're already getting the source maps for yous scss
files (to verify that you need to have a file with the same name as you css, but with a .map
on its name), so the only thing you will need is to peroperly configure your browser to load and use the source maps. This example uses Google Chrome:
- Open dev tools
- Click the gear icon or three dots to open settings (top right corner)
- Under General (or Preferences), look for the “Sources” section. In that section, select “Enable CSS source maps”.
- Make sure the accompanying “Auto-reload generated CSS” is also enabled (if available). This last step helps to reload the CSS when it changes. Think of it like a live reload feature for the CSS alone.
- Navigate to your localhost server, inspect any element on your page.
- In the developer tools, choose the Sources tab.
- In the file tree on the left hand side, right-click your stylesheet and select “Map to file system resource…”. This will bring up the file search dialog. Select the appropriate file (your stylesheet). In some newer versions of Chrome, the file should be loaded automatically using the
/*# sourceMappingURL=style.css.map */
reference - Restart the developer tools.
That should work. Let me know. Otherwise i will fine tune the quick tutorial.
CSS Sourcemaps not generating properly with gulp, SASS, & autoprefixer
You can use gulp-sourcemaps if you switch to gulp-sass
. Both gulp-sass
and gulp-autoprefixer
support gulp sourcemaps.
Implementation would look something like:
var gulp = require('gulp');
var gulpSass = require('gulp-sass');
var gulpAutoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('javascript', function() {
gulp.src('src/**/*.scss')
.pipe(sourcemaps.init())
.pipe(gulpSass())
.pipe(gulpAutoprefixer())
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('dist'));
});
Which would write .map files in a maps directory.
Note: All manipulations from source .scss to target .css must be in the stream between sourcemaps.init()
and sourcemaps.write()
. This includes any minification such as gulp-uglify
, which also supports gulp-sourcemaps
.
Chrome not loading CSS source maps?
You can try the following steps:
1- delete the map file and regenerate it again.
2- Using the chrome inspector, go to Settings > General and then click on the button "Restore defaults and reload"
SASS sourcemaps not working in Google Chrome
It turns out that auto-prefixer was running on the compiled CSS and stripping out the sourceMapURL comment, which now makes sense that it would do that, because unless you have auto-prefixer source maps turned on (which I did not), it would make the source maps untrue. A cool thing I learned form this, is that auto-prefixer is apparently able to use Sass source maps to make it's own, and keep everything true to the Sass files.
I actually wish there was a warning whenever auto-prefixer finds source maps, but doesn't have source maps enabled itself, because it's obvious that tasks shouldn't generate sourcemaps that wont be used.
I would have been more likely get an answer sooner if I would have posted my whole Gruntfile, but it's a lot of stuff, and I was trying scale back to code I thought was relevant. Darn.
Related Topics
CSS Circle Border Fill Animation
Evenly-Spaced Navigation Links That Take Up Entire Width of Ul in CSS3
Rake Assets:Precompile Throws SASS::Syntaxerror: Invalid CSS After "*/"
CSS - Removing Horizontal Space in List Menu Using Display: Inline Property
How to Put Custom Content Like a Linebreak Inside P:Column Header
CSS - Apply Opacity to Element But Not to Text Within the Element
ASP.NET MVC 5 - Stylebundle Cdnfallbackexpression Questions
Inline Svg Breaks in Safari and Mobile Safari
R - How to Plot Dygraphs in Multiple Panels
How to Load One Style Sheet for Mobile Devices and One for Desktops
Internet Explorer Creates Horizontal Scrollbar for Vertical Scrollbar's Width
Make Hexagon Shape with Border, Rounded Corners and Transparent Background
Jquery Mobile Android - Fixed Full-Screen Background Image
How Often Is the Default Font Size in the Browser Not 16Px
Css: How to Attach an Arrow to a Div and Make It Overlap the Border
Can It Flexbox? Chat Window with Input at the Bottom, Chats Scrolling Up