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.

Autoprefixer Breaks CSS Source Maps

See original GitHub issue

Here’s my gruntfile.js:

module.exports = function(grunt) {

    // Load Grunt tasks declared in the package.json file
    require('load-grunt-tasks')(grunt);

    grunt.initConfig({
        sass: {
        options: {
            sourceMap: true
        },
            dist: {
                files: {
                    'user/themes/br/css-compiled/bobmess.css': 'user/themes/br/scss/bobmess.scss'
                }
            }
        },

        autoprefixer: {
            dist: {
                src: 'user/themes/br/css-compiled/bobmess.css'
            }
        },

        watch: {
            scss: {
                files: ['user/themes/br/scss/*.scss'],
                tasks: ['sass', 'autoprefixer'],
            },

            livereload: {
                files: ['user/**/*.{css,md,twig,js,yaml}'],
                options: {
                    livereload: true
                }
            }
        }
    });

    grunt.registerTask('default', ['watch']);
};

Running it creates a css file and a source map with LibSass via grunt-sass. But Chrome does not recognize the source map. If I comment out the autoprefixer task, the source map is recognized by Chrome. I’ve tried it with grunt-contrib-sass (which uses Ruby Sass) and I find the same behavior.

It seems as if autoprefixer is messing up the source map, or the reference to it, somehow.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bobrockecommented, Mar 1, 2015

I eventually got it working with:

module.exports = function(grunt) {

    // Load Grunt tasks declared in the package.json file
    require('load-grunt-tasks')(grunt);

    grunt.initConfig({
        sass: {
            options: {
                sourceMap: true
            },
            dist: {
                files: {
                    'user/themes/br/css-compiled/bobmess.css': 'user/themes/br/scss/bobmess.scss'
                }
            }
        },

        autoprefixer: {
            options: {
                map: true
            },
            dist: {
                src: 'user/themes/br/css-compiled/bobmess.css'
            }
        },

        watch: {
            scss: {
                files: ['user/themes/br/scss/*.scss'],
                tasks: ['sass', 'autoprefixer'],
            },

            livereload: {
                files: ['user/**/*.{css,md,twig,js,yaml}'],
                options: {
                    livereload: true
                }
            }
        }
    });

    grunt.registerTask('default', ['watch']);
};

Explicitly turning on source maps for autoprefixer was the trick for me.

1reaction
jonathantnealcommented, Feb 19, 2015

This issue is not limited to grunt. For example: sindresorhus/gulp-autoprefixer#1, floridoo/gulp-sourcemaps#60, dlmanning/gulp-sass#106, appleboy/gulp-compass#92

We can produce a bogus sourcemap by adding gulp-sass to the current gulp example.

gulp.task('autoprefixer', function () {
    var postcss      = require('gulp-postcss');
    var sourcemaps   = require('gulp-sourcemaps');
    var autoprefixer = require('autoprefixer-core');
    var sass         = require('gulp-sass');

    return gulp.src('./src/*.css')
        .pipe(sourcemaps.init())
        .pipe(sass())
        .pipe(postcss([ autoprefixer({ browsers: ['last 2 version'] }) ]))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('./dest'));
});

One work-around has been to roll back gulp-sass to ~1.2.4 and to re-initialize sourcemaps before Autoprefixer is run.

gulp.task('autoprefixer', function () {
    var postcss      = require('gulp-postcss');
    var sourcemaps   = require('gulp-sourcemaps');
    var autoprefixer = require('autoprefixer-core');
    var sass         = require('gulp-sass');

    return gulp.src('./src/*.css')
        .pipe(sourcemaps.init())
        .pipe(sass())
        .pipe(sourcemaps.write('.'))
        .pipe(sourcemaps.init({ loadMaps: true }))
        .pipe(postcss([ autoprefixer({ browsers: ['last 2 version'] }) ]))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('./dest'));
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

autoprefixer breaks trying to parse node-sass sourcemap
I'm trying to rewrite my workflow using NPM scripts. I want to: convert all .scss files > css > autoprefix > minify >...
Read more >
postcss - npm
The Autoprefixer PostCSS plugin is one of the most popular CSS processors. ... const sourcemaps = require('gulp-sourcemaps').
Read more >
Advanced Features: Customizing PostCSS Config - Next.js
Extend the PostCSS config and plugins added by Next.js with your own. ... Source Maps · Codemods · Internationalized Routing · Output File...
Read more >
PostCSS API
Simple CSS concatenation with source map support const root1 = postcss.parse(css1, { from: file1 }) ... Returning false in the callback will break...
Read more >
Solution to no CSS source map file generated under ...
The issue is in Webpack 4 under "production" mode there is no source map file generated only for CSS (no problem in javascript...
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