Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Sass always shows line number for parent selector in sourcemaps when using autoprefixer #771

Closed
linkurzweg opened this issue Jan 11, 2017 · 9 comments

Comments

@linkurzweg
Copy link

See this issue here:
gulp-sourcemaps/gulp-sourcemaps#161

When using autoprefixer, sourcemaps stop working correctly for nested selectors. They always show the line number of the parent selector. When I remove autoprefixer everything works fine.

The author of gulp-sourcemaps points out this is a problem with autoprefixer, not with the sourcemaps plugin. Could you please look into this?

@ai
Copy link
Member

ai commented Jan 11, 2017

Autoprefixer is just a PostCSS plugin. All work for CSS transformation and source maps is in PostCSS :).

@ai
Copy link
Member

ai commented Jan 11, 2017

I think this issue is related postcss/postcss#926

@ai ai closed this as completed Jan 11, 2017
@linkurzweg
Copy link
Author

Ah, alright, I didn't know that. Thanks for the info, I'll subscribe to the postcss issue then :)

@cyphix333
Copy link

I don't think this has to do with postCSS at all as I'm not using postCSS in my build; eg;

gulp.task('styles', function() {
    return gulp.src('scss/**/*.scss')
        .pipe(sourcemaps.init())
        .pipe(sass().on('error', sass.logError))
        .pipe(autoprefixer({
            browsers: [
                'last 4 Chrome versions',
                'last 4 Firefox versions',
                'last 4 Edge versions',
                'last 2 Safari versions',
                'ie >= 10',
                '> 1.49%',
                'not ie <= 9'
            ],
            cascade: false
        }))
        .pipe(sourcemaps.write('../maps'))
        .pipe(gulp.dest('./css/'));
});

So it can't have to do with postCSS.

@ai
Copy link
Member

ai commented Feb 18, 2017

@cyphix333 there is no way to use Autoprefixer without PostCSS. Autoprefixer is just a PostCSS plugins.

So you are PostCSS user even if you use gulp-autoprefixer, because it just use PostCSS inside https://github.com/sindresorhus/gulp-autoprefixer/blob/master/index.js#L6

Also please migrate from gulp-autoprefixer to gulp-postcss. I have issue reports about gulp-autoprefixer every few week, only gulp-postcss is a official way.

@cyphix333
Copy link

cyphix333 commented Feb 18, 2017

Oh ok thanks, That's good to know and also answers my question I had on SO last year :)

@SenHengDesamis
Copy link

cross posting from gulp-sourcemaps/gulp-sourcemaps#161

I've been having this issue and the only way I've managed to fix it is to run both autoprefixer and cssNano together. I'd prefer to not minify when local dev because there's a legacy stylesheet with 20k lines in it... but this was the only thing that worked.

Maps work perfectly fine in Chrome, a little bit funky in FF (sometimes goes to closing bracket) and breaks in Safari (Goes to parent).

const gulp = require('gulp');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const gulpIf = require('gulp-if');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const nano = require('cssnano');

const processors = [
  autoprefixer({browsers: ['last 2 version']}),
  nano(),
];

gulp.task('sass', () =>
  gulp.src(config.main)
    .pipe(gulpIf(env === 'dev', sourcemaps.init()))
    .pipe(sass(config.settings))
    .on('error', handleErrors)
    .pipe(postcss(processors))
    .pipe(gulpIf(env === 'dev', sourcemaps.write()))
    .pipe(gulp.dest(config.dest))
);

versions

"autoprefixer": "^7.1.5",
"cssnano": "^4.0.0-rc.2",
"gulp": "3.9.1",
"gulp-postcss": "^7.0.0",
"gulp-sass": "^3.1.0",
"gulp-sourcemaps": "^2.6.1",

@cyphix333
Copy link

I just wish someone would fix this problem so we didn't have to rely on workarounds.

@ai
Copy link
Member

ai commented Oct 16, 2017

Use PostCSS based preprocessors, they don't have compatible issue since they use same parser and AST 😏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants