question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use in combination with gulp-sass

See original GitHub issue

Hi,

Im trying to use gulp-autoprefixer in combination with gulp-sass and gulp-sourcemaps. My gulpfile task looks like this:

gulp.task('sass', function () {
  gulp.src( config.SASS.src )
    .pipe( plugins.sourcemaps.init() )
    .pipe( plugins.sass() )
    .pipe( plugins.autoprefixer (
      "last 1 versions", "> 10%", "ie 9"
      ))
    .pipe( plugins.sourcemaps.write('./') )
    .pipe( gulp.dest( config.SASS.build ) )
    .pipe( browserSync.reload({ stream: true }) );
});

The plugins. prefix is related to gulp-load-plugins

Without gulp-sass the task runs fine, but with it it throws the following error:

[08:26:51] Finished 'sass' after 3.32 ms
gulp-sourcemap-write: source file not found:/Users/luismartins/Sites/00_LAB/wp-multisite/wp-content/themes/wip053/src/sass/main.css

Should I be running autoprefixer as a separate task after CSS compilation?

Thanks.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:53 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
subbluecommented, Oct 9, 2014

I’ve had all the various sourcemap problems reported when trying to use gulp-sass, gulp-sourcemap and gulp-autoprefixer. After fiddling around for ages this is the final task template that works for me:

gulp       = require('gulp');
sass       = require('gulp-sass'); // 1.0.0
sourcemaps = require('gulp-sourcemaps');  // v1.2.2
autoprefix = require('gulp-autoprefixer');  // v1.0.1

gulp.task('styles', function() {
  return gulp.src('src/scripts/app/app.scss')
    .pipe(sourcemaps.init())
    .pipe(sass({errLogToConsole: true}))
    .pipe(sourcemaps.write({includeContent: false, sourceRoot: '.'}))

    .pipe(sourcemaps.init({loadMaps: true}))
    .pipe(autoprefix({browsers: ['last 1 version', 'iOS 6'], cascade: false}))
    .pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: '../scripts/app'}))

    .pipe(gulp.dest('www/css'));
});

The things that made it work for me are wrapping sourcemaps calls around the sass and autoprefixer separately, passing the maps from the first into the second (with loadMaps) and the includeContent and sourceRoot options passed into the sourcemaps.write() methods.

Because the source maps don’t include the original content I’m allowing my dev server access to the original .scss files too, so that from the Chrome dev console I can click on the scss file name and view the original source directly. The dev console actually feels a little snappier this way too with large stylesheets.

The line numbering to the original file is slightly out due to autoprefixer adding the additional prefixed lines, but the important thing is that very quickly and with low friction I can find the style settings in the original .scss file.

1reaction
pjlongcommented, May 1, 2015

@justnorris. Looks like @ahdinosaur’s solution was working all along. You will have to upgrade to gulp-sass 2.x branch, however: npm install dlmanning/gulp-sass#2.x (and make sure to update to the most recent node-sass as well).

Here’s the bare-bones implementation:

gulp.task('sass', function () {
    return gulp.src(paths.css.src_files)
        .pipe(sourcemaps.init())
            .pipe(sass())
        .pipe(sourcemaps.write())
        .pipe(sourcemaps.init({loadMaps: true}))
            .pipe(autoprefixer())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(paths.css.dist));
});

Note: this is only for inline maps, I don’t think I’ve successfully got external maps to work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

gulp-sass - npm
Start using gulp-sass in your project by running `npm i gulp-sass`. There are 2411 other projects in the npm registry using gulp-sass.
Read more >
Using Gulp and UnCSS in Combination with Sass based ...
Today I'll show you how we can use a Gulp build process to establish a convenient way to work on Hugo themes. Furthermore,...
Read more >
Combining SCSS and SASS syntax with Gulp? - Stack Overflow
The plus + and parentheses () allows Gulp to match multiple patterns, with different patterns separated by the pipe | character. In this...
Read more >
compiling Sass to CSS with gulp-sass plugin - ZetCode
The gulp-sass is a Gulp plugin for compiling Sass to CSS. Internally it uses the node-sass module. Installing Gulp and gulp-sass. We initiate...
Read more >
Sass to CSS > Gulp! Refreshment for Your Frontend Assets
The problem is that it's not a CSS file at all - it's a Sass file that lives in app/Resources/assets . Btw, this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found